HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
Any URLs added here will be added as <link>
s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
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.
Using packages here is powered by Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
// 6. Работа с математическими функциями
// ============================================================================
var name = 'Работа с математическими функциями';
console.log('Урок № 6 - ' + name);
// ============================================================================
// ============================================================================
console.log('Работа с %');
// ============================================================================
/*
1. Даны переменные a = 10 и b = 3. Найдите остаток от деления a на b.
*/
var a = 10;
var b = 3;
var result = a % b;
console.log(result);
// ============================================================================
/*
2. Даны переменные a и b. Проверьте, что a делится без остатка на b. Если это
так - выведите 'Делится' и результат деления, иначе выведите
'Делится с остатком' и остаток от деления.
*/
var a = 2;
var b = 10;
var result = b % a;
if (result == 0) {
console.log('Делиться: ' + 'ответ - ' + b / 2);
} else if (result != 0) {
console.log('Делиться с остатком: ' + 'остаток - ' + result);
}
var a = 3;
var b = 10;
var result = b % a;
if (result == 0) {
console.log('Делиться: ' + 'ответ - ' + b / a);
} else if (result != 0) {
console.log('Делиться с остатком: ' + 'остаток - ' + result);
}
// ============================================================================
console.log('Работа со степенью и кормем');
// ============================================================================
/*
3. Возведите 2 в 10 степень. Результат запишите в переменную st.
*/
var st = console.log(Math.pow(2, 10));
// ============================================================================
/*
4. Найдите квадратный корень из 245.
*/
var num = 245;
console.log(Math.sqrt(num));
// ============================================================================
/*
5. Дан массив с элементами 4, 2, 5, 19, 13, 0, 10. Найдите квадратный корень из
суммы кубов его элементов. Для решения воспользуйтесь циклом for.
*/
var array = [4, 2, 5, 19, 13, 0, 10];
var result = 0;
for (var i = 0; i < array.length; i++) {
result = result + Math.pow(array[i], 3);
}
console.log(Math.sqrt(result));
// ============================================================================
console.log('Работа с функциями округления');
// ============================================================================
/*
6. Найдите квадратный корень из 379. Результат округлите до целых, до десятых,
до сотых.
*/
var num = Math.sqrt(379);
console.log('Результат квадратного корня из 379 - ' + num);
console.log('Результат округления до целых функцией Math.round - ' + Math.round(num));
// or
console.log('Результат округления до целых функцией floor - ' + Math.floor(num));
// or
console.log('Результат округления до целых функцией parseInt - ' + parseInt(num));
// or
console.log('Результат округления до целых методом to.Precision - ' + (num.toPrecision(2)));
// or
console.log('Результат округления до целых методом toFixed - ' + (num.toFixed()));
console.log('Результат округления до десятых методом toPrecision - ' + (num.toPrecision(3)));
// or
console.log('Результат округления до десятых методом toFixed - ' + (num.toFixed(1)));
console.log('Результат округления до сотых методом toPrecision- ' + (num.toPrecision(4)));
// or
console.log('Результат округления до сотых методом toFixed - ' + (num.toFixed(2)));
// ============================================================================
/*
7. Найдите квадратный корень из 587. Округлите результат в большую и меньшую
стороны, запишите результаты округления в объект с ключами 'floor' и 'ceil'.
*/
var num = Math.sqrt(587);
console.log(num);
var object = { floor: Math.floor(num), ceil: Math.ceil(num) };
console.log('Результат округления floor = ' + object.floor);
console.log('Результат округления ceil = ' + object.ceil);
// ============================================================================
console.log('Нахождение максимального и минимального числа');
// ============================================================================
/*
8. Даны числа 4, -2, 5, 19, -130, 0, 10. Найдите минимальное и максимальное
число.
*/
var array = [4, -2, 5, 19, -130, 0, 10];
console.log('Минимальнае число из массива = ' + Math.min.apply(null, array));
console.log('Максимальное число из массива = ' + Math.max.apply(null, array));
// or
console.log('Минимальное число = ' + Math.min(4, -2, 5, 19, -130, 0, 10));
console.log('Максимальное число = ' + Math.max(4, -2, 5, 19, -130, 0, 10));
// ============================================================================
console.log('Работа с рандомом');
// ============================================================================
/*
9. Выведите на экран случайное целое число от 1 до 100
*/
function getRandomInt(min, max) {
return (Math.floor(Math.random() * (max - min + 1) + min));
}
console.log(getRandomInt(1, 100));
// or
console.log(Math.floor(Math.random() * (100 - 1 + 1) + 1));
// ============================================================================
/*
12. Заполните массив 10-ю случайными целыми числами.
*/
var array = [];
var min = 1;
var max = 100;
for (var i = 0; i < 10; i++) {
array[i] = Math.floor(Math.random() * (max - min + 1) + min);
console.log(array[i]);
}
// or
var max = 100;
var array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
for (var i = 0; i < array.length; i++) {
array[i] = Math.floor(Math.random() * (max - array[i] + 1) + array[i]);
console.log(array[i]);
}
// ============================================================================
/*
11. Даны переменные a и b. Найдите модуль разности a и b. Проверьте
работу скрипта самостоятельно для различных a и b.
*/
var a = 10;
var b = 12;
console.log(Math.abs(a - b));
// ============================================================================
console.log('Работа с модулем');
// ============================================================================
/*
12. Даны переменные a и b. Отнимите от a переменную b и результат присвойте
переменной c. Сделайте так, чтобы в любом случае в переменную c записалось
положительное значение. Проверьте работу скрипта при a и b,
равных соответственно 3 и 5, 6 и 1.
*/
var a = 3;
var b = 5;
var c = (Math.abs(a - b));
console.log(c);
var a = 6;
var b = 1;
var c = (Math.abs(a - b));
console.log(c);
// ============================================================================
console.log('Задачи');
// ============================================================================
/*
13. Дан массив arr. Найдите среднее арифметическое его элементов. Проверьте
задачу на массиве с элементами 12, 15, 20, 25, 59, 79.
*/
var arr = [12, 15, 20, 25, 59, 79];
var result = 0;
for (var i = 0; i < arr.length; i++) {
arr[i] = arr[i] / arr.length;
result = result + arr[i];
console.log('Среднее арифметическое каждого элемента массива = ' + arr[i]);
}
var arr = [12, 15, 20, 25, 59, 79];
var result = 0;
for (var i = 0; i < arr.length; i++) {
result = result + arr[i];
}
console.log('Среднее арифметическое элементов массива = ' + result / arr.length);
// ============================================================================
/*
14. Напишите скрипт, который будет находить факториал числа. Факториал
(обозначается !) - это произведение (умножение) всех целых чисел, меньше
данного, и его самого. Например, 4! = 1*2*3*4.
*/
var factorial = 5;
var count = 1;
var result = 1;
for (var i = 2; i <= factorial; i++) {
count = count + '*' + i;
result = result * i;
}
console.log(factorial + '! = ' + count + ' = ' + result);
Also see: Tab Triggers