Tell us what’s happening:
Hi everyone. English is not my native language , I’m sorry if there are some errors in spelling or grammar.
I got two problem with this lecture.
The first:
I know the code works but I don’t understand why the result is 5040.
Can someone show me the math behind it?
The other problem is the following:
I know " for (var i = 0; i < arr.length; i++) " checks the number of arrays.
I know " for (var j = 0; j < arr[i].length; j++ " checks the numbers in the arrays.
But it only checks the length of the numbers.
The actual array is passed into the function as argument as I understand it.
How does the function calculate with the arguments when I only check the length of an array?
I’m sorry this all might sound weird but I can’t explain it any better.
Maybe some one can explain this whole function to me at a very basic level?
Your code so far
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 = product * arr[i][j];
}
// 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/86.0.4240.183 Safari/537.36
.
Challenge: Nesting For Loops
Link to the challenge: