AMGZ
1
var temperature = 20;
var itsRaining = false;
var idealnaTemperature = 20;
var n;
var minutes;
if(itsRaining || temperature < 0 || temperature > 35){
minutes = 0;
}else if(temperature == 20){
minutes = 20;
}else{
if(temperature > idealnaTemperature){
n = temperature - idealnaTemperature;
minutes = idealnaTemperature - n;
}else if(temperature < idealnaTemperature){
minutes = temperature;
}
}
1 лайк
Можно немного проще.
var temperature = 35;
var itsRaining = false;
var idealTemperature = 20;
var minutes;
if (temperature < 0 || temperature > 35 || itsRaining) {
minutes = 0;
} else if (temperature > 20 && temperature <= 35) {
minutes = idealTemperature - ( temperature - idealTemperature);
}
1 лайк
можно исчо проще =) без else
var temperature = 20;
var itsRaining = false;
var minutes = 0;
if(temperature>0 && temperature<35 &&!itsRaining) {minutes = 20 - Math.abs(20 - temperature)};
3 лайка
del32a
7
такого ещо кекс не расказивал
2 лайка
if (itsRaining || temperature<0 || temperature>35) {
minutes = 0;
console.log('Прогулка не состоится!');
} else {
minutes = 20 - Math.abs(20 - temperature);
}