freeCodeCamp Challenge Guide: Nesting For Loops

.length = items in array

[0,1,2,3]

array length is 4 items

4 = arr.length

4 Likes

Thanks for asking that - I was so confused when var j suddenly appeared!

1 Like

Great challenge!

Math works like this:

I got this using these codes:

function multiplyAll(arr) {
  var product = 1;
  // Only change code below this line
  for (i = 0; i < arr.length; i++) {
    for (j = 0; j < arr[i].length; j++) { 
      console.log(product *=arr[i][j]); // consolidates the value of [i] and [j] and assign it to **product**
    }
  }
  // Only change code above this line
  return product;
}

// Modify values below to test your code
multiplyAll([[1,2],[3,4],[5,6,7]]);
38 Likes
function multiplyAll(arr) {
  var product = 1;
  // Only change code below this line
  for (var i = 0; i < arr.length; i++) {
    for (var j = 0; j < arr[i].length; j++) {
      product *= arr[i][j];
    }
  }
  // Only change code above this line
  return product;
}

// Modify values below to test your code
multiplyAll([[1,2],[3,4],[5,6,7]]);
1 Like

To the @narendra67 @thelynguist @wansim… you made my day to move on for next steps … personally thank you guys :slight_smile:

2 Likes