Длительность прогулки

Можно скобки убрать :joy:

1 лайк

let temperature = 20;
let isRaining = true;
let minutes = 0;
if (!isRaining) {
if (temperature>=10 && temperature<15) {minutes=30}
else if (temperature >=15 && temperature<25) {minutes=40}
else if (temperature >=25 && temperature<=35) {minutes=20}
}


можно тернарным оператором)

let temperature = 20;
let isRaining = true;
let minutes = 0;
if (!isRaining) {
(temperature>=10 && temperature<15) ? minutes=30:
(temperature >=15 && temperature<25) ? minutes=40:
(temperature >=25 && temperature<=35) ? minutes=20 :
minutes = 0;
}

100%

let temperature = 20;
let itsRaining = false;
let minutes;
if (itsRaining || temperature < 0 || temperature >35) {minutes = 0}
else {minutes = 20 - Math.abs(20 - temperature)}

let temperature = 20;
let itsRaining = false;

let minutes;

if (itsRaining || temperature <= 0 || temperature >= 35) {
minutes = 0;
console.log(‘я никуда не выхожу: либо очень холодно, либо очень жарко’);
} else if (temperature == 20) {
minutes = 20;
console.log(‘я гуляю ’ + minutes + ’ минут’)
} else if (temperature > 0 && temperature < 20) {
minutes = temperature;
console.log(‘я гуляю ’ + minutes + ’ минут’)
} else if (temperature > 20 && temperature < 35) {
minutes = 20 - (temperature - 20);
console.log(‘я гуляю ’ + minutes + ’ минут’)
};

Коротко и изящно

let temperature = 20;
let itsRaining = false;

let minutes;

if (itsRaining || temperature <0 || temperature > 35) {
minutes = 0;
} else if (temperature >= 0 && temperature <= 20) {
minutes = temperature;
} else if (temperature >20 && temperature <= 35) {
minutes = temperature - (temperature - 20) * 2;
}

2 лайка

Так совсем ничего лишнего!)
let temperature = 20;
let isRaining = false;
let minutes = 0;

if (isRaining || temperature < 10 || temperature > 35) {
minutes = 0;

} else {

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 itsRaining = false;
let minutes;

if (itsRaining || temperature < 0 || temperature > 35) {minutes = 0}
else if (temperature <= 20) {
minutes = temperature;}
else if (temperature > 20) {
minutes = (20 + 20) - temperature;}

let temperature = 20;
let itsRaining = false;

let minutes;

if (itsRaining ||temperature < 0 || temperature > 35) {
minutes = 0;
} else if ((temperature > 20 && temperature <= 35) || (temperature < 20 && temperature >= 0)) {
minutes = 20 - Math.abs(temperature - 20);
} else {
minutes = temperature;
}

let temperature = 20;
let itsRaining = false;

let minutes;

if (itsRaining) {
minutes = 0;
} else
if (temperature < 0 && temperature > 35) {
minutes = 0;
} else
if (temperature === 20) {
minutes = 20;
} else {
if (temperature < 20) {
minutes = 20 - (20 - temperature);
} else if (temperature > 20 && temperature <= 40) {
minutes = 20 - (temperature - 20);
} else if (temperature > 40) {
minutes = 0
}
}

let temperature = 20;
let itsRaining = false;
let superTemperature = 20;
let minutes;
if (itsRaining || temperature < 0 || temperature > 35) {
minutes = 0;
} else minutes = 20 - Math.abs(superTemperature-temperature);

let temperature = 20;
let itsRaining = false;

let minutes;

if (itsRaining || temperature < 0 || temperature > 35) {
minutes = 0;
} else {
minutes = 20 - Math.abs(20 - temperature);
}

1 лайк

let temperature = 15;
let isRaining = false;
let minutes = 0;

if (isRaining) {
minutes = 0;
console.log(minutes);
}

if (!isRaining) {
if (temperature > 10 && temperature < 15 && !isRaining) {
minutes = 30;
console.log(minutes);
}
}
if (temperature >= 15 && temperature < 25 && !isRaining) {
minutes = 40;
console.log(minutes);
}
if (temperature >= 25 && temperature <= 35 && !isRaining) {
minutes = 20;
console.log(minutes);
}

      if (temperature > 35 || temperature < 10) {
        console.log('Слишком холодно или жарко');
        };

Самый лаконичный и простой способ решения!

Не проходит проверку на 15 и 22 градусах, помогайте

let temperature = 20;
let itsRaining = false;

let minutes;

if (itsRaining = true || temperature < 0 || temperature > 35) {
minutes = 0;
}

else if (temperature == 20) {
minutes = 20;
}

else if (temperature > 20) {
minutes = 20 - (temperature - 20);

}

else if (temperature < 20) {
minutes = 20 - (20 - temperature);
}

let temperature = 20;
let itsRaining = false;
let minutes;

if(itsRaining===true || temperature<0 || temperature>35){
minutes=0;
}else if(temperature===20){
minutes=20;
}else if(temperature<20||temperature>20){
minutes=20-Math.abs(temperature-20);
}

1 лайк

if (itsRaining = true || temperature < 0 || temperature > 35) {
Поставьте === вместо =
= это оператор присвоения.

1 лайк

Если интересно можете упростить код через логическое ИЛИ в конце

let temperature = 20;
let itsRaining = false;

let minutes;

if((itsRaining==true)||(temperature<0)||(temperature>35)){
minutes=0}else if(temperature===20){minutes=20}
else{minutes=20-Math.abs(temperature-20)}

let temperature = 20;
let itsRaining = false;
let minutes;

if (itsRaining || temperature <=0 || temperature >= 35) {
minutes = 0;}
else { minutes= 20 - Math.abs (20 - temperature) }