Question 12
Back to Exercise
The code below runs without an error, but its result is wrong. Which statement correctly identifies the bug?
const answer = "yes";
if (answer === "Yes") {
console.log("Subscribed");
} else {
console.log("Not subscribed");
}
- A === cannot compare strings
- B The else branch always runs
- C === is case-sensitive – compare answer.toLowerCase() === "yes" Correct
- D answer must be declared with let
Correct Answer: Option C
"yes" and "Yes" are different strings. Normalise user input (trim and lower-case) before comparing.
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!