let temperature = 15;
let isRaining = true;
let minutes = 0;
if (isRaining || temperature > 36 || temperature < 9){
minutes = 0;
}
else if (!isRaining && temperature >= 10 && temperature <= 14) {
minutes = 30;
}
else if (!isRaining && temperature >=15 && temperature <=24) {
minutes = 40;
}
else if (!isRaining && temperature >=25 && temperature <=35) {
minutes = 20;
} else {
minutes = 0;
};
let temperature = 35;
let isRaining = false;
let minutes = 0;
if (!isRaining) {
if (temperature >= 10 && temperature < 15) {minutes = 30}
if (temperature >= 15 && temperature < 25) {minutes = 40}
if (temperature >= 25 && temperature <= 35) {minutes = 20}
} else {
minutes = 0
}
let temperature = 20;
let isRaining = true;
let minutes = 0;
if (temperature >=10 && temperature <=35 && !isRaining) {
if (temperature < 25) {
if (temperature < 15) {
minutes = 30;
}
else {
minutes = 40;
}
}
else {
minutes = 20;
}
}
let temperature = 20;
let isRaining = true;
let minutes = 0;
if(!isRaining){
if(temperature < 15 && temperature > 10){
console.log(minutes = 30);
}
else if(temperature >= 15 && temperature < 25){
console.log(minutes = 40)
}
else if(temperature >= 25 && temperature <= 35){
console.log(minutes = 20)
}
else{
console.log(minutes = 0)
}
}
let temperature = 25;
let isRaining = false;
let minutes = 0;
if (isRaining === true && minutes === 0 && temperature <= 9) {
console.log('Идёт дождь, гулять я не иду');
}
if ((isRaining === false) && (temperature >= 10 && temperature <= 14)) {
minutes = 30;
console.log(‘Я иду гулять на ’ + minutes + ’ минут’) ;
}
if ((isRaining === false) && (temperature >= 15 && temperature <= 24)) {
minutes = 40;
console.log(‘Я иду гулять на ’ + minutes + ’ минут’) ;
}
if ((isRaining === false) && (temperature >= 25 && temperature <= 35)) {
minutes = 20;
console.log(‘Я иду гулять на ’ + minutes + ’ минут’) ;
}
let temperature = 20;
let isRaining = true;
let minutes = 0;
if (temperature >= 10 && temperature < 15 && !isRaining) {
minutes = 30;
} else if (temperature >= 15 && temperature < 25 && !isRaining) {
minutes = 40;
} else if (temperature >= 25 && temperature <= 35 && !isRaining) {
minutes = 20;
} else {
minutes = 0;
};
Самое интересное, что у всех разные варианты решения)
А вот какой код чище - загадка.
let temperature = 24;
let isRaining = false;
let minutes = 0;
if(isRaining || temperature < 10 || temperature > 35){
console.log(‘Гулять буду ’ + minutes + ’ минут’);
}else if (isRaining && temperature >= 10 || temperature < 15){
minutes = 30;
console.log(‘Гулять буду ’ + minutes + ’ минут’)
}else if (isRaining && temperature >= 15 || temperature < 25){
minutes = 40;
console.log(‘Гулять буду ’ + minutes + ’ минут’)
}else if (isRaining && temperature >= 25 || temperature <= 35){
minutes = 20;
console.log(‘Гулять буду ’ + minutes + ’ минут’)
}
Пипец вы тут нагородили, в ваших вариантах чёрт ногу сломит прежде, чем разберётся во всех условиях. Вот самый простой понятный вариант основанный на уроках из темы.
let temperature = 20;
let isRaining = true;
let minutes = 0;
if (!isRaining) {
if (temperature >= 10 && temperature < 15) {
minutes = 30;
}
if (temperature >= 15 && temperature < 25) {
minutes = 40;
}
if (temperature >= 25 && temperature <= 35) {
minutes = 20;
}
}
let temperature = 20;
let isRaining = true;
let minutes = 0;
if (!isRaining && temperature >= 10 && temperature <= 35) {
if (temperature < 15) {
minutes = 30;
} else if (temperature < 25) {
minutes = 40;
} else {
minutes = 20;
}
} else {
minutes = 0;
}