LearnFrenzy
Sign in Take a free test

Arrays · Find the Error · Question 14

Bug: identical answers marked wrong Answer, explanation & discussion

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

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

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

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links