Reinitializing Variables Inside a Loop - solution

Hi all,
I passed the challenge using a different solution than what was given. Is this still acceptable? I now know they were after using the let row variable in the for loop instead of what I did.

  **Your code so far**

function zeroArray(m, n) {
// Creates a 2-D array with m rows and n columns of zeroes
let newArray = [];
let row = [];
for (let i = 0; i < m; i++) {
  // Adds the m-th row into newArray

  for (let j = 1; j < i; j++) {
    // Pushes n zeroes into the current row to create the columns
  // Pushes the current row, which now has n zeroes in it, to the array
return newArray;

let matrix = zeroArray(3, 2);
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36 Edg/92.0.902.55

Challenge: Use Caution When Reinitializing Variables Inside a Loop

Link to the challenge:

you have not fixed the bug tho, try to check results with different inputs

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.