Nesting For Loops-help

Tell us what’s happening:

hello I’ve executed this i would like someone to review my code and let me know where i did wrong, i am confiedent that i did it right, but i can not see the wrong portion i did… i will keep on going through

Your code so far

function multiplyAll(arr) {
  var product = 1;
  // Only change code below this line
  for (p = 0; p<arr.length; p++){
    for (var sArray = 0; sArray < arr[p];sArray++){
      return product *= arr[p][sArray];
    }
  }
  // Only change code above this line
  return product;
}

// Modify values below to test your code
multiplyAll([[1,2],[3,4],[5,6,7]]);

Your browser information:

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

Link to the challenge:
https://www.freecodecamp.org/challenges/nesting-for-loops

I figure out some mistake(i will put it on bold what i corrected ), but still the code doesn’t work;
function multiplyAll(arr) {
var product = 1;
// Only change code below this line
for (var p = 0; p<arr.length; p++){
for (var sArray = 0; sArray < arr[p];sArray++){
return product *= arr[p][sArray];
}
}

Yes, that was an easy syntax mistake, but you made several others. In your second for-loop, the condition your iterator must be less than is not the length of the nested array, it is only less than the value of that nested array.

sArray < arr[p].length;

Second, you are returning the multiplication in your second for-loop. This exits the entire function on the very first value of the first array, not that it would have iterated properly without the above correction. Remove your return keyword in your second for-loop.

While it is best to include those declarative variable keywords, you can get away with not doing so because JS fills in the gaps, but you made some other mistakes that you were sure were not there.

1 Like

thank you, for you help, i actually coorected the
"sArray < arr[p].length;" before you pointed out; and anyway thank you for you help;
My wonder now is that why wasn’t executing properly with the “return” keyword!!

Thank you for you guidance in advance

I see the answer to my previous question thank you again

i would love to see them and get the behave of my code when those mistake are runing

If you made all of those changes, the function should work now.