Copy link to clipboard
Copied
Hi,
I have this code:
for (var i = 0; i < 5; i++) {
var count = 0;
var loopEnd = Math.floor(Math.random() * 5 + 1);
for (var j = 0; j < loopEnd; j++) {
count++;
}
//alert(count);
}
var arr = Array();
function arrAdd(count){
arr.push(count);
}
alert (arr.length);
that gives me only one element. I'd need to be able to get all the 5 numbers randomized in the new array. Is there a way to do that?
Cheers
Copy link to clipboard
Copied
Hi,
I have this code:
for (var i = 0; i < 5; i++) {
var count = 0;
var loopEnd = Math.floor(Math.random() * 5 + 1);
for (var j = 0; j < loopEnd; j++) {
count++;
}
//alert(count);
}
var arr = Array();
function arrAdd(count){
arr.push(count);
}
alert (arr.length);
that gives me only one element. I'd need to be able to get all the 5 numbers randomized in the new array. Is there a way to do that?
Cheers
Copy link to clipboard
Copied
You have to build the array inside the main loop. Of course the loop itself will only return the last valid value.
Mylenium