--- id: 56533eb9ac21ba0edf2244e1 title: Nesting For Loops localeTitle: Anidando para bucles challengeType: 1 --- ## Description
Si tiene una matriz multidimensional, puede usar la misma lógica que el punto de ruta anterior para recorrer tanto la matriz como cualquier subarreglo. Aquí hay un ejemplo:
var arr = [
  [1,2], [3,4], [5,6]
];
for (var i=0; i < arr.length; i++) {
  for (var j=0; j < arr[i].length; j++) {
    console.log(arr[i][j]);
  }
}
Esto genera cada subelemento en arr uno a la vez. Tenga en cuenta que para el bucle interno, estamos comprobando la .length de arr[i] , ya que arr[i] es en sí misma una matriz.
## Instructions
Modificar la función multiplyAll para que multiplique la variable del product por cada número en las subarreglas de arr
## Tests
```yml tests: - text: ' multiplyAll([[1],[2],[3]]) debe devolver 6 ' testString: 'assert(multiplyAll([[1],[2],[3]]) === 6, "multiplyAll([[1],[2],[3]]) should return 6");' - text: ' multiplyAll([[1,2],[3,4],[5,6,7]]) debe devolver 5040 ' testString: 'assert(multiplyAll([[1,2],[3,4],[5,6,7]]) === 5040, "multiplyAll([[1,2],[3,4],[5,6,7]]) should return 5040");' - text: ' multiplyAll([[5,1],[0.2, 4, 0.5],[3, 9]]) debe devolver 54 ' testString: 'assert(multiplyAll([[5,1],[0.2, 4, 0.5],[3, 9]]) === 54, "multiplyAll([[5,1],[0.2, 4, 0.5],[3, 9]]) should return 54");' ```
## Challenge Seed
```js 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]]); ```
## Solution
```js function multiplyAll(arr) { var product = 1; for (var i = 0; i < arr.length; i++) { for (var j = 0; j < arr[i].length; j++) { product *= arr[i][j]; } } return product; } multiplyAll([[1,2],[3,4],[5,6,7]]); ```