Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Can u please explain to me how these 2 loops work together? Thank you.

function multiplyAll(arr) { var product = 1; for (var i = 0; i < arr.length; i++) { for (var j = 0; j < arr[i].length; j++) { product = product * arr[i][j]; } } return product; } multiplyAll([[1,2],[3,4],[5,6,7]]);

1 Answer

Hi Tony. Please try this. I tried to transcribe it. I am not sure how this is the good way.

function multiplyAll(arr) { 
  var product = []; 
  for (var i = 0; i < arr.length; i++) { 
  for (var j = i; j < arr.length; j++) { 
  product = arr[i] * arr[j]; 
  } } 
  return product; 
  } 
multiplyAll([[1,2],[3,4],[5,6,7]]);
cconsole.log(product[i]);