How do we multiple product with array?

The question ask

Modify function multiplyAll so that it multiplies the product variable by each number in the sub-arrays of arr

I don’t know what is being asked, as product = 1 and how we multiply with each array? e.g [2,4]. so it means 12 = 4 and 14 = 4 but what is next. The question is confusing

Your code so far


function multiplyAll(arr) {
var product = 1;
// Only change code below this line

// 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:

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

Challenge: Nesting For Loops

Link to the challenge:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/nesting-for-loops

The challenge expects your function multiplyAll to take the two dimensional array passed to it and multiply all the elements of the inner arrays together.

For example, if the following call was made to your function:

multiplyAll([[1,2],[3,4],[5,6,7]]);

your function would multiple 1 x 2 x 3 x 4 x 5 x 6 x 7 and return the value 5040.

You will need to iterate through the main array elements (which are arrays also) and then iterate through these “sub-arrays” also to get all the values needed for the creation of the product.

2 Likes

Thanks, sometimes It is had to understand/breakdown what is being asked.