In JavaScript Write an Array Containing 10 Arrays
Posted on June 8, 2015 in Algorithms, JavaScript by Matt Jennings
In JavaScript create an array containing 10 arrays. Those 10 separate arrays should each contain a randomly selected string value of "D"
or "E"
.
/* Single Array that will eventually contain 10 randomly selected values of "D" or "E" */ var x = []; // Array that will contain 10 separate versions of the x array var y = []; for(var k = 0; k < 10; k++) { for(var i = 0; i < 10; i++) { var rand = Math.floor(Math.random() * 2); if(rand == 1) { rand = "D"; } else { rand = "E"; } x.push(rand); } y.push(x); // Assign x array to an empty array to reset the values x = []; } console.log(y);