I just realized my error where the tempRndNumber was being reset in the inner loop. Although, I am still encountering an issue where "," characters are appearing in the array.
The goal is to create a 2D array that is populated only when a random number meets a specific condition (rnd >= 7). However, the current code is filling the 2D array with a combination of "," and the numbers that meet the criteria.
var tempAllRndNumbers = [];
for (var i = 0; i < 10; i++) {
for (var j = 0; j < 10; j++) {
var tempRndNumber = [];
var rndNumber = Math.floor(Math.random() * 10);
if (rndNumber >= 7) {
tempRndNumber.push(rndNumber);
}
}
tempAllRndNumbers.push(tempRndNumber);
}
My expectation was that tempAllRndNumbers would only contain numbers 7 and above. However, I am observing that the 2D array is filled with both "," and numbers 7 and above.