Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                
              
            
!

CSS

              
                
              
            
!

JS

              
                //  example
  const obj = {
    a:1,
    b:2,
    c:3
  };
  for(let key in obj) {
    console.log(key);//a,b,c
    console.log(obj);//{a:1,b:2,c:3
    console.log(obj[key]);//1,2,3
    console.log()
  }

  //	example
  // Метод hasOwnProperty() возвращает логическое значение, указывающее, содержит ли объект указанное свойство.

  function sum(obj) {
    let sum = 0;
    for(let el in obj) {
      if(obj.hasOwnProperty(el)){
        sum += parseFloat(obj[el]);
      }
    }
    return sum;
  }

  const sample = {a:1,b:2,c:3};
  const summed = sum(sample);
  console.log("sum:" + summed);//sum:6

  //	example
/*
Как выполнить цикл или перечислить объект JavaScript?
  У меня есть JavaScript-объект, например:

var p = {
  "p1": "value1",
  "p2": "value2",
  "p3": "value3"
};*/


const p = {
  "p1": "value1",
  "p2": "value2",
  "p3": "value3"
};

for(let key in p) {
  if(p.hasOwnProperty(key)) {
    console.log(key + "->" +p[key] );//p1-> value1,p2-> value2,p3-> value3,
  }
}
//example
  const obj = {0: 'x', 1: 'y', 2: 'z'};
  // const obj = {вася:'200', петя:'30', ира:'4444'};
  for (key in obj) {
    console.log(Object.keys(obj[key]));//200 = ['0','1','2'] 30 = ['0','1'] 4444 = ['0','1','2','3']
    console.log(Object.keys(obj));//['вася','петя','ира']
  }
  console.log(Object.keys(obj[key]));//выводит самое длинное число['0','1','2','3']

  //	работа с переменными
  function num(num1, num2) {
    let a = num1;
    let b = num2;
    let result = b % a;
    if (result == 0) {
      console.log('делится ' + b / a);
    } else if (result !== 0) {
      console.log('делится с отстатком' + 'остаток=' + result)
    }
    return result;
  }

  console.log(num(10, 20));
  
//  example
  const arr = [4, 2, 5, 19, 13, 0, 10];
  let sum = 0;
  for (let i = 0; i < arr.length; i++) {
    sum += Math.round(Math.sqrt(arr[i]));
  }
  console.log(sum);//16*/
  // Math.sqrt-ищет квадратный корень
  // Math.round - округляет до целых в большую сторону
  //Math.floor --округляет в меньшую сторону
  // parseInt -округление до целых
  const arr = [4, 2, 5, 19, 13, 0, 10];
  let sum = 0;
  arr.forEach((elem) => {
    return sum += parseInt(Math.sqrt(elem));
  });
  console.log(sum);//16
  const obj = {
    floor: Math.floor(sum),
    ceil: Math.ceil(sum),
    round: Math.round(sum),
    parseInt: parseInt(sum)
  };
  // округлим в большую и в меньшую сторону
  console.log(obj.floor);//15
  console.log(obj['floor'])//15
  console.log(obj.ceil);//15
  console.log(obj['ceil']);//15
  console.log(obj.parseInt)



  let arr = [4,-2,5,19,-130,0, 10];

  console.log(Math.min.apply(null,arr));//-130
  console.log(Math.min(4,-2,5,19,-130,0, 10));//-130


  console.log(Math.max.apply(null,arr));//19
  console.log(Math.max(4,-2,5,19,-130,0, 10));//19
	
//	example
/*Найдите сумму наибольшего и наименьшего элементов массива.*/

function minNumSumm(obj) {
  let a = obj[0];
  let b = obj[0];
  let summ = 0;

  for (let i = 0; i < obj.length; i++) {
    if((obj[i] < a)|| (obj[i]>b)) {
      a = obj[i] + obj[i];
      b = obj[i] + obj[i];
      summ = a + b;
    }
    console.log(a);//4,-2,6
    console.log(b); //4,-2,6
    console.log(summ);//0,-4,12
  }
  return summ;
}

const elemArr = [4,-1,3];
console.log(minNumSumm(elemArr));//12

              
            
!
999px

Console