What do you think about this solution ? JavaScript Course

True, but remember the newArray variable is only referencing whatever the row variable carries. So, if row includes extra two zeros, the previous row arrays inside newArray will readjust to the current value of row. Hope this helps.

1 Like

Thank you very much! @haywae Your short explanation did it for me. Kevin also helped greatly.

1 Like

Looking for some clarification. In the initial (unedited) code, the output occurs on three visually distinct rows. However, when the solution code is executed, the three arrays appear visually on one row. Is this intended, or am I missing the meaning of “row” in this exercise? Thanks in advance.

Are you just talking about the formatting of the console.log output?

If you use JSON.stringify it should put it back on one line.

console.log(JSON.stringify(matrix));

Formatting just changes the look of the output, it doesn’t change the data structure.

I used this and it worked

for (let j = 0; j < n; j++) {
  // Pushes n zeroes into the current row to create the columns
 
  if(row.length==n){break} else { row.push(0);}
 
  console.log(row)
}

  }
  return newArray;
}

let matrix = zeroArray(3, 2);
console.log(matrix);