Nesting for loops help!

hi! I getting this error: “ReferenceError: product is not defined” but i have the var product = 1; in one of my lines… I dont get which is the problem…

var arr = [[1,2],[3,4],[5,6,7]];

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;



this one is out of the function, product is not defined in the global frame

I’ve edited your post for readability. 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.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

1 Like

Thanks! I did what you say and pass the exercice.

But i dont understand why i get an error with the console.log, is not suposed to be like a “comment”? (i know that it is not a comment, but i think it is a term only to know what i am having as results in the real code. I mean, i think about the console.log as a term that doesnt alterate my code) .

whatever you put inside the console.log is evaluated, it is not a comment, it’s a piece of code that can give errors if something’s wrong

1 Like

ok! i get it now! Many thanks