# The nesting For loops

Tell us what’s happening:
Hi, I need help. I do understand the For loops, at least most of them. I am stuck at the lesson of The Nesting For Loops, I want to know all the hows and whys, so far, i do understand all the way to 5040 ( where’s it comes from and how to get there) , however, I do not understand where’s the ([5,1],[0.2,4,0.5],[3,9]) come from and how it should return 54? Thank you

``````  **Your code so far**
``````
``````
function multiplyAll(arr) {
var product = 1;
// Only change code below this line

// 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 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36`

Challenge: Nesting For Loops

What have you tried so far? That looks like the starter code.

In this challenge, you need to multiply together every number in every sub array to make one big product of all of those numbers.

Hi, sorry, i meant Nesting For Loops. `multiplyAll([[5,1],[0.2, 4, 0.5],[3, 9]])` should return `54` .
Would you please tell me how to get to 54 and where’s the [0.2,4,0.5] come from?

What do you get if you multiply together every single number in those nested arrays?

The `[0.2, 4, 0.5]` is just a sub-array that you’ve been given.

`multiplyAll([[1,2],[3,4],[5,6,7]])` should return `5040`
1234567 (12=2 23=6 34=6x4=24 and so on) keep on going till 5040

Yes. And the challenge wants you to do that for any nested arrays with nested loops.

Would you please break down the 1st and 2nd set of product*=arr[i][j] from
multiplyAll([[1,2],[3,4],[5,6,7]]);

I don’t understand what you are asking. I’m not going to write out the solution for you.

`arr[i][j]` is how you index into nested arrays to get a single number. You need a loop over all sub arrays and a loop over all numbers in each sub array. You need to multiply each number together inside of that nested pair of loops.

``````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;
}

multiplyAll([[1,2],[3,4],[5,6,7]]);
``````

I’ve edited your post for readability and added spoiler tags. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (`</>`) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

Sorry, I got it. Thanks

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