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 - (temperature - 20);
}
else if (temperature < 20) { minutes = 20 - (20 - temperature);
}
Моё решение, так коротко можно делать?
let temperature = 35;
let itsRaining = true;
let minutes;
if (itsRaining || temperature < 0 || temperature >35) {
minutes = 0;
} else {
minutes = 20 - Math.abs(temperature - 20);
}
Вариант 1:
let temperature = 15;
let itsRaining = false;
let minutes;
if(itsRaining || temperature < 0 || temperature > 35) {
minutes = 0;
} else {
minutes = 20 - Math.abs(20 - temperature);
}
Вариант 2:
let temperature = 15;
let itsRaining = false;
let minutes;
(itsRaining || temperature < 0 || temperature > 35) ?
minutes = 0 : minutes = 20 - Math.abs(20 - temperature);