Nested for loops

by trentHarlem

HTML

<p id='screen'></p>
<p id='product'></p>

JavaScript

function multiplyALL(array) {
  var ourArray = [
    [1, 2],
    [3, 4, 5],
    [6, 7, 8],
    [9, 10]
  ];
  
  var product = 1;

  var pushedArray = []; //must declare outside of loop so push will append.

  for (var i = 0; i < array.length; i++) {
    console.log('Parent', [i]);
    for (var j = 0; j < array[i].length; j++) {
      console.log('--------> Child', [j]);
      product *= array[i][j];

      var numbers = []; //must declare inside loop to always have one number	
      numbers.push(array[i][j]);
      console.log(numbers); // to show numbers in 'Child index'
      pushedArray.push(array[i][j]); // to show numbers on screen

    }
    var cleanUp = pushedArray.join(' *'); // to change ',' delimiter to a ' *'
    document.getElementById('screen').innerHTML = cleanUp;
    document.getElementById('product').innerHTML = (`= ${product}`);
  }
  return product;
}

multiplyALL([[1, 2],[3, 4, 5],[6, 7, 8],[9, 10]])