# Basic JavaScript - Nesting For Loops

so I had to ask you a question: calculate how much it will be in this example, and not say what it is, in my understanding it is an array, and if you need to count it will be 6

I’m trying to tell you how it works.

Do you know what one times two times three is? The problem is asking you to multiply everything from every subarray together into one big product.

There is no ‘count’. Nothing is being added together. This problem is about multiplication.

Whatever translation tool you are using might not be doing a very good job.

Do you know what one times two times three is
I think 1 is product = 1, and 1,2,3 is the array arr[i]

1 * 1, 1 * 2, 1 * 3 I think so

Nope. That’s not how multiplication works. I didn’t ask for ‘one times one’ and ‘one times two’ and ‘one times three’. You made three separate, different problems instead of answering the one problem I asked. ‘one times two times three’. I’m asking you what number you get when you multiply those three numbers together all at the same time.

that will be six ,if I need to do arithmetic

Yes.

`1*2*3` is equal to `6`

Which is what this test is saying here. If you multiply all of the numbers in all of the subarrays together, you get 6.

`multiplyAll([[1, 2], [3, 4], [5, 6, 7]])` should return `5040`

This one is saying that you need to do `1*2"3*4*5*6*7`

Since the function argument is an array full of subarrays, you need nested loops to access all of the individual numbers.

`multiplyAll([[1, 2], [3, 4], [5, 6, 7]])` должен вернуться `5040`
I understand the arithmetic, but I don’t understand how this happens in the code, where everything is added, why first it came out 2, then 24 and after 5040, I don’t know how it all works

Well, there isn’t code for this yet. You need to write it!

The example showed how to loop over an array. Do you have questions about the example?

Using the example, I understand how it works, but what I asked you is not clear to me.

Can you write a loop that `console.log`s each subarray of the `arr`?

``````function multiplyAll(arr) {
let product = 1;
// Only change code below this line
for(let i = 0; i< arr.length; i++){
for(let j = 0; j<arr[i]; j++){
console.log(arr[i][j])
}

}
// Only change code above this line
return product;
}

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

but for some reason the code does not output the array separately, but in the example it works without problems,

Ok, here you’re actually printing out each element of the subarrays, but this is what I was going to ask for next.

You have each number in each subarray. Can you multiply `product` by each `arr[i][j]`?

I think yes, it’s possible.

Give it a try

``````function multiplyAll(arr) {
let product = 1;
// Only change code below this line
for(let i = 0; i< arr.length; i++){
for(let j = 0; j<arr[i]; j++){
product =  product * arr[i][j]
}
console.log(product)
}
// Only change code above this line
return product;
}

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

no it doesn’t work

Say more. In what way does it not work?

You have a small bug, but we might be able to logic it out

prints 1 1 1 to the console

So it seems like the inner loop is never running.

Let’s look at the loop head

The initialization and increment look ok. This sort of problem is often in the bound. What’s `j < arr[i]` mean? That’s suspicious to me.

But this doesn’t tell me anything, I can’t even imagine in my head how the code works, how it iterates through the array, where it saves it or always just iterates, I don’t know anything, I think the array [1], 2 is stored in arr[i] ], [3, 4], [5, 6, 7]

You don’t need to imagine anything. You have the code in front of you.

Can you say what `j < arr[i]` does? You’re right that `arr[i]` is an array. So can you compare a number and an array with the <No, you can’t. What is it about the subarray that you want to iterate over?