Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function weatherForecast2 (input) {
- let degrees = Number(input[0]);
- let weather = "";
- if (degrees >= 5 && degrees < 12) {
- weather = "Cold";
- } else if (degrees >= 12 && degrees < 15) {
- weather = "Cool";
- } else if (degrees >= 15 && degrees <= 20) {
- weather = "Mild";
- } else if (degrees > 20 && degrees < 26) {
- weather = "Warm";
- } else if (degrees >= 26 && degrees <= 35) {
- weather = "Hot";
- } else {
- weather = "unknown";
- }
- console.log(weather);
- }
- РЕШЕНИЕ С ТЕРНАРЕН ОПЕРАТОР:
- function weatherForecast2(input) {
- let degrees = Number(input[0]);
- let weather =
- degrees >= 5 && degrees < 12 ? "Cold" :
- degrees >= 12 && degrees < 15 ? "Cool" :
- degrees >= 15 && degrees <= 20 ? "Mild" :
- degrees > 20 && degrees < 26 ? "Warm" :
- degrees >= 26 && degrees <= 35 ? "Hot" : "unknown";
- console.log(weather);
- }
- ИЛИ:
- function weatherForecast2(input) {
- let degrees = Number(input[0]);
- console.log(
- degrees >= 5 && degrees < 12 ?
- "Cold" :
- degrees >= 12 && degrees < 15 ?
- "Cool" :
- degrees >= 15 && degrees <= 20 ?
- "Mild" :
- degrees > 20 && degrees < 26 ?
- "Warm" :
- degrees >= 26 && degrees <= 35 ?
- "Hot" :
- "unknown"
- );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement