How to multiply all the numbers in the sub-arrays of arr

Tell us what’s happening:
Describe your issue in detail here.

  **Your code so far**

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

multiplyAll([[1,2],[3,4],[5,6,7]]);
  **Your browser information:**

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

Challenge: Nesting For Loops

Link to the challenge:

I’m not quite sure what you need help with.

I see the issue, but how about this:
Take a piece of paper and try to write down what your code is doing - you should only multiply 7 numbers so that’s shouldn’t cause a problem in writing.

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.

the solution to your question is almost completly given in the lesson description.
You have an array of arrays. You want to loop thru every element of the top array, and loop thru every number in that element(array).
You can do that using nested for loops. The tricky part is making sure you target the right element on every loop iteration, using the syntax to refer to an array elements, in the current challenge it would look like

arrayName[position of a sub-array][position of an item in sub-array]
     0          1          2           //positions in main array
    0  1      0  1      0  1  2        //positions in sub-arrays
[ [ 1, 2 ], [ 3 ,4 ], [ 5, 6, 7 ] ]

EDIT: on every iteration you want to multiply the previous product by the current number. The product is being accumulated as the loops go

Point noted. Thank you

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