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
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?
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.