Nesting for loops multiplication

Tell us what’s happening:

Does anyone know why my code isn’t working? I saw it was nearly the exact same as the solution and I couldn’t tell where I went wrong with the syntax

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[j][j];
// Only change code above this line
return product;

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36.

Challenge: Nesting For Loops

Link to the challenge:

you could do with just one loop if you are using just one variable - is that what you want?

1 Like

Also, try logging i to see how many times your outer loop actually runs.

Hey @iangoodman!

The problem line of code has already been pointed out to you by @ilenia.

If you feel yourself copying the FCC solution might I add a piece of advice. I would pause on this problem and take a moment to understand how nested loops really work.

I would get out a pen and paper and write out what is really happening within the nested loops. Go step by step starting with the outer loop, checking if the condition is true and then moving inside the inner loop. Walk through each step carefully like a computer would and you will start to understand what is happening.

Hope that helps!

Happy coding!