DEV Community

20. Operators (if, else if, else, ternary operator, switch)

The given code checks the temperature and prints "Hot" if it's above 25, "Warm" if it's between 15 and 25, and "Cold" if it's below 15. The temperature is set to 30, so the output is "Hot". In the second part, the code uses an if-else statement to determine the day of the week based on the integer value. The day is set to 3, which corresponds to Wednesday. The code can be simplified using a switch statement. In the third part, the code checks if a number is greater than 5 and assigns a string accordingly. The number is set to 10, so the output is "Greater than 5". This code can be simplified using a ternary operator.
favicon
dev.to
dev.to