Cold-room alert
A food store classifies a cold-room reading. Print COLD below 2 degrees, OK from 2 through 5 degrees inclusive, and WARM above 5 degrees.
Input
One line: a decimal temperature.
Output
One line: COLD, OK or WARM.
Example 1
Input
4.5
Output
OK
4.5 lies inside the inclusive safe range.
Constraints
- -50 <= temperature <= 100
Hints
Hint 1 of 3
Test the lower boundary first.
Hint 2 of 3
Reaching the second branch already means the value is at least 2.
Hint 3 of 3
Use <= 5 so the upper boundary stays safe.
Solution
Show a reference solution and explanation
const temperature = Number(readline());
if (temperature < 2) {
console.log('COLD');
} else if (temperature <= 5) {
console.log('OK');
} else {
console.log('WARM');
}
Why it works
The ordered branches partition all possible readings without gaps. Testing the thresholds directly also makes the inclusive and exclusive boundaries visible to the reader.
Lesson for this exercise: Conditions in JavaScript: if, else if, else and switch