So I’m really stuck on this one. I think I got the hang of loops up till now, but adding nesting is throwing me totally. I know I need to do multiplication somewhere in the loop, but I’m not sure how.
I know this must work something like accessing nested arrays in previous lessons, but I can’t get my head around it.
Any help welcome.
function multiplyAll(arr) {
let product = 1;
// Only change code below this line
for (let i = 0; i < arr.length; i * i) {
for (let j = 0; j < arr[i].length; j * j) {
product = arr[i][j];
console.log(product);
}
}
// 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 (iPad; CPU iPhone OS 15_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) FxiOS/102.0 Mobile/15E148 Safari/605.1.15
No because i thought I knew how to do it, I passed the lesson before but have forgotten and I literally solved it today but already forgot it. I am very embarrassed.
Hi I’ve looked at these and ran them in codepen (except the ones that were really advanced and I haven’t leaned about yet) but I still don’t understand how to apply that to this lesson. I managed to solve the Iterate Through an Array with a For Loop Lesson again.
But I still don’t know how to solve this lesson. I feel like I’m just trying to jam code in to make it work.
I don’t understand why I can’t make the multiplication work.
function multiplyAll(arr) {
let product = 1;
// Only change code below this line
for (let i = 0; i < arr.length; i++){
for (let j = 0; j < arr[i].length; j++){
product = i * j;
}
}
// Only change code above this line
return product;
}
multiplyAll([[1, 2], [3, 4], [5, 6, 7]]);