Question 14
Back to Exercise
The code below runs without an error, but its result is wrong. Which statement correctly identifies the bug?
const correct = ["B", "D", "A"];
const answered = ["B", "D", "A"];
console.log(answered === correct ? "All correct" : "Some answers wrong");
- A Strings in arrays cannot be compared
- B The arrays must be sorted first
- C === compares references, not contents – compare lengths and each element: a.every((x, i) => x === b[i]) Correct
- D The ternary needs parentheses
Correct Answer: Option C
Two separate arrays are never ===. answered.length === correct.length && answered.every((x, i) => x === correct[i]) checks the contents.
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!