<-- Start of s4.14\2.1.html -->
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Из дюймов в сантиметры</title>
</head>
<body>
<h1>Пересчет величин</h1>
<script type="text/javascript">
let ins = window.prompt('Величина в дюймах', 0);
ins = ins.replace(',', '.');
if (ins == null)
window.document.write('<p>Величина не была введена</p>');
else {
let s;
switch(Math.floor(ins)) {
case 1:
s = 'дюйм';
break;
case 2:
case 3:
case 4:
s = 'дюйма';
break;
default:
s = 'дюймов';
}
window.document.write('<p>', ins, ' ',s , '</p>');
const cents = ins * 2.54;
window.document.write('<p>', cents, ' см.</p>');
}
</script>
</body>
</html>
<-- End of s4.14\2.1.html -->
<-- Start of s4.14\4.14.1.html -->
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Среднее арифметическое</title>
</head>
<body>
<h1>Среднее арифметическое</h1>
<script type="text/javascript">
const s = window.prompt('Введите список чисел', '');
const cs = s.split(',');
let sum = 0;
cs.forEach((el) => {sum += +el;});
const avg = sum / cs.length;
window.document.write('<p>', avg, '</p>');
</script>
</body>
</html>
<-- End of s4.14\4.14.1.html -->
<-- Start of s4.14\4.14.2.html -->
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Текущая дата</title>
</head>
<body>
<h1>Текущая дата</h1>
<script type="text/javascript">
const d = new Date();
const months = ['января', 'февраля', 'марта', 'апреля', 'мая',
'июня', 'июля', 'августа', 'сентября', 'октября', 'ноября',
'декабря'];
window.document.write('<p>Сегодня ', d.getDate(), ' ',
months[d.getMonth()], ' ', d.getFullYear(), ' г.</p>');
</script>
</body>
</html>
<-- End of s4.14\4.14.2.html -->
<-- Start of s4.14\4.14.3.html -->
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Тригонометрические функции</title>
</head>
<body>
<h1>Тригонометрические функции</h1>
<table>
<tr><th>Угол</th><th>sin</th><th>cos</th><th>tg</th></tr>
<script type="text/javascript">
let angle, ar;
const c = Math.PI / 180;
for (angle = 0; angle <= 90; angle += 15) {
ar = angle * c;
window.document.write('<tr>');
window.document.write('<td>', angle, '</td>');
window.document.write('<td>', Math.sin(ar), '</td>');
window.document.write('<td>', Math.cos(ar), '</td>');
window.document.write('<td>', Math.tan(ar), '</td>');
window.document.write('</tr>');
}
</script>
</table>
</body>
</html>
<-- End of s4.14\4.14.3.html -->
<-- Start of s4.14\4.14.4.html -->
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Сортировка чисел</title>
</head>
<body>
<h1>Сортировка чисел</h1>
<script type="text/javascript">
const s = window.prompt('Введите список чисел', '');
const cs = s.split(',');
cs.sort((el1, el2) => {
let e1 = +el1, e2 = +el2;
if (e1 % 2 == 0 && e2 % 2 != 0)
return -1;
else if (e1 % 2 != 0 && e2 % 2 == 0)
return 1;
else
return e1 - e2;
});
window.document.write('<p>', cs.join(', '), '</p>');
</script>
</body>
</html>
<-- End of s4.14\4.14.4.html -->
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<title>Дюймы в сантиметры</title>
</head>
<body>
<script>
let input = prompt("Введите длину в дюймах (с точкой или запятой):");
input = input.replace(',', '.'); // заменяем запятую на точку
let inches = parseFloat(input);
if (!isNaN(inches)) {
let cm = inches * 2.54;
document.write(inches + " дюйма = " + cm.toFixed(2) + " см");
} else {
document.write("Ошибка: введите число.");
}
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<title>Среднее арифметическое</title>
</head>
<body>
<script>
let input = prompt("Введите числа через запятую:");
let arr = input.split(',').map(n => parseFloat(n.trim()));
let sum = arr.reduce((a, b) => a + b, 0);
let avg = sum / arr.length;
document.write("Среднее: " + avg.toFixed(2));
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<title>Текущая дата</title>
</head>
<body>
<script>
let now = new Date();
let day = now.getDate();
let monthNames = ['января','февраля','марта','апреля','мая','июня','июля','августа','сентября','октября','ноября','декабря'];
let month = monthNames[now.getMonth()];
let year = now.getFullYear();
document.write(`Сегодня ${day} ${month} ${year} г.`);
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<title>Тригонометрия</title>
</head>
<body>
<table border="1" cellpadding="5">
<tr><th>Угол</th><th>sin</th><th>cos</th><th>tan</th></tr>
<script>
let angles = [0, 15, 30, 45, 60, 75, 90];
for (let angle of angles) {
let rad = angle * Math.PI / 180;
document.write(`<tr><td>${angle}°</td><td>${Math.sin(rad).toFixed(4)}</td><td>${Math.cos(rad).toFixed(4)}</td><td>${Math.tan(rad).toFixed(4)}</td></tr>`);
}
</script>
</table>
</body>
</html>
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<title>Чётные и нечётные</title>
</head>
<body>
<script>
let input = prompt("Введите числа через запятую:");
let arr = input.split(',').map(n => parseInt(n.trim()));
let evens = arr.filter(n => n % 2 === 0);
let odds = arr.filter(n => n % 2 !== 0);
let result = evens.concat(odds);
document.write("Результат: " + result.join(', '));
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Текущая дата и время</title>
</head>
<body>
<h1>Текущая дата и время</h1>
<script type="text/javascript">
const d = new Date();
// Месяцы на русском в родительном падеже
const months = ['января', 'февраля', 'марта', 'апреля', 'мая',
'июня', 'июля', 'августа', 'сентября', 'октября', 'ноября',
'декабря'];
// Получаем часы и минуты
let hours = d.getHours(); // часы (0–23)
let minutes = d.getMinutes(); // минуты (0–59)
let seconds = d.getSeconds(); // секунды (0–59)
// Добавим ведущий 0 к минутам и секундам (например, 09:03)
if (minutes < 10) minutes = '0' + minutes;
if (seconds < 10) seconds = '0' + seconds;
if (hours < 10) hours = '0' + hours;
// Собираем вывод
window.document.write('<p>Сегодня ',
d.getDate(), ' ',
months[d.getMonth()], ' ',
d.getFullYear(), ' г.</p>');
window.document.write('<p>Текущее время: ',
hours, ':', minutes, ':', seconds, '</p>');
</script>
</body>
</html>
Если заменить n => parseFloat(n.trim()) на обычную функцию:
js
Копировать
Редактировать
function convert(n) {
let withoutSpaces = n.trim();
let number = parseFloat(withoutSpaces);
return number;
}
let arr = parts.map(convert);
То будет то же самое.
🔁 Упражнение для тебя
Попробуй сам:
js
Копировать
Редактировать
let input = " 1.5, 2.75 , 4";
let arr = input.split(',').map(n => parseFloat(n.trim()));
console.log(arr);