 # Nesting For Loops exercise error message

Nesting For Loops exercise error message
0

Tell us what’s happening:
I have double checked the code I used for this exercise and in the end I’ve also used the version provided by freeCodeCamp.

I am stacked, I know the code is correct as it works in real.it; but I keep receiving different code error like :
multiplyAll([[1,2],[3,4],[5,6,7]]) should return 5040
multiplyAll([[5,1],[0.2, 4, 0.5],[3, 9]]) should return 54

or

TypeError: unknown: undefined is not an object (evaluating ‘o[a]’)

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.length; j++){
product = product * arr[i][j];
}
}
// Only change code above this line
return product;
}
``````
``````
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.length; j++){
product = product * arr[i][j];
}
}
// Only change code above this line
return product;
}

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

Your browser information:

User Agent is: `Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1.1 Safari/605.1.15`.

Why are you limiting j to be less than the length of the 2nd element of arr? What if there are 3 elements or 4 elements in arr?

1 Like

what if the inner arrays have different lengths? what if there is not an array at index 1?

Guys I am sorry this arr.length was meant to be arr[i].length.

Thank you for your eagle eye 