Temperature Check
Programming Basics · JavaScript
TASK
Problem
Given temperature `t`, print `FREEZING` if `t < 0`, `NORMAL` for `0 ≤ t ≤ 30`, and `HOT` for `t > 30`.
EXAMPLE
Example
31
HOT
LIMITS
Constraints
All numeric input values fit in JavaScript `Number`.
LEARN
Theory for this problem
+
### Temperature Check
`if / else if / else` chooses a branch from boolean conditions. Comparisons such as `<`, `>=`, `===` and logical operators `&&`, `||`, `!` combine the exact rules that decide which output is valid.
NEED HELP?
Hints
+
['Translate every case from the statement into a boolean condition before writing branches.', 'Check values exactly on the condition boundary: `=`, `<`, and `>` must match the statement without an off-by-one shift.']
ANSWER
Solution
+
const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trimEnd();
let t = Number(input);
if (t < 0) {
console.log("FREEZING");
} else {
if (t <= 30) {
console.log("NORMAL");
} else {
console.log("HOT");
}
}