LearnFrenzy
Sign in Take a free test

Operators · Find the Error · Question 13

Bug: every temperature is "comfortable" Answer, explanation & discussion

  • Find the error
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 13 Back to Exercise

The code below runs without an error, but its result is wrong. Which statement correctly identifies the bug?

main.js
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!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links