I am stuck at this task, please, help me out some

Tell us what’s happening:

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++){
console.log(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/84.0.4147.105 Safari/537.36.

Challenge: Nesting For Loops

Link to the challenge:

You did not tell us what kind of help you need.

1 Like

Hi Randal
I need a help…

What is the issue you are experiencing.

it didn’t work, what can I do to modify this code:

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++){

console.log(product+=arr[i][j]);

}

}

// Only change code above this line

return product;

}

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

product+=arr[i][j];

Explain what you think this line is doing.

Do you understand what the product of two numbers is?

lets look a little closer at
the chalenge preamble

put this in the code execution window

var arr = [
  [1,2], [3,4], [5,6]
];
for (var i=0; i < arr.length; i++) {
console.log('[ outer',i ,'] contains ...');
  for (var j=0; j < arr[i].length; j++) {
    console.log('( inner',j,') = ',arr[i][j]);
  }
}

logs

[ outer 0 ] contains …
( inner 0 ) = 1
( inner 1 ) = 2
[ outer 1 ] contains …
( inner 0 ) = 3
( inner 1 ) = 4
[ outer 2 ] contains …
( inner 0 ) = 5
( inner 1 ) = 6

the challenge is asking you to
“find the product of all the inners”
like this …
outer0(inner0)*(inner1)*outer1(inner0)*(inner1)*outer2(inner0)*(inner1)

Ok so here’s a hint:
Declare a variable and set it equal to 1. And everytime you loop through each element, multiply that element with the variable. And finally return that variable.