Question 13
Back to Exercise
The code below runs without an error, but its result is wrong. Which statement correctly identifies the bug?
const temp = 45;
if (10 < temp < 30) {
console.log("Comfortable");
} else {
console.log("Extreme");
}
- A < cannot compare a number with a variable
- B temp must be a string
- C 10 < temp gives true, and true < 30 is 1 < 30 – always true; write temp > 10 && temp < 30 Correct
- D The else branch needs braces
Correct Answer: Option C
Chained comparisons are evaluated left to right on booleans. A range test needs two comparisons joined by &&.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!