LearnFrenzy
Sign in Take a free test

Arrays · Find the Error · Question 12

Bug: marking one seat books a whole column Answer, explanation & discussion

  • Find the error
  • Hard
  • 0 comments
  • Answer explained
  • Moderated community
Question 12 Back to Exercise

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

main.js
const seats = new Array(3).fill(new Array(3).fill("."));
seats[0][1] = "X";                  // book row 0, seat 1
console.log(seats.map((row) => row.join("")).join("\n"));
  • A join("") changes the seats
  • B Rows must be strings
  • C fill puts the same inner array in every row, so changing one row changes all – build rows with Array.from({ length: 3 }, () => new Array(3).fill(".")) Correct
  • D Indexes start at 1
Correct Answer: Option C

The outer fill copies one reference three times. Array.from with a function creates a fresh row per index, so only row 0 changes.

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