-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
39 lines (36 loc) · 1.42 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const body = document.querySelector('body');
const cities = ['Пуэрто-Вальярта', "Челябинск", "Екатеринбург", "Белград"];
const temperatures = [];
const degreeSign = String.fromCharCode(176);
(() => {
const div = document.createElement('div');
body.appendChild(div);
let i = 0;
for (city of cities) {
temperatures[i++] = prompt(`Введите температуру в ${city}`);
}
i = 0;
for (city of cities) {
const tempInCity = document.createElement('p');
tempInCity.textContent = `Температура в городе ${city}: ${temperatures[i++]}${degreeSign}C`;
div.appendChild(tempInCity);
}
const maxTemp = document.createElement('h2');
maxTemp.textContent = `Максимальная температура: ${maxOfArray(temperatures)}${degreeSign}C`;
body.appendChild(maxTemp);
const minTemp = document.createElement('h2');
minTemp.textContent = `Минимальная температура: ${minOfArray(temperatures)}${degreeSign}C`;
body.appendChild(minTemp);
})();
function maxOfArray(array) {
const min = -1000;
let max = min;
for (elem of array) max = (+elem > max) ? +elem : max;
return max;
}
function minOfArray(array) {
const max = 1000;
let min = max;
for (elem of array) min = (+elem < min) ? +elem : min;
return min;
}