Hey guys I’m trying to run a loop with a setInterval but I would like each element in the array to use a random interval instead of the entire array doing so… this is the code I am using so far
setInterval(function() {
for ( var j = 0; j < aliens.length; j++ ){
aliens[j].shootIt();
}
}, 1000+Math.floor(Math.random() * 4000)
);
but I’m kind of stuck here… Thanks in advance!!!
Move the
forloop to outside the interval, then call a function on each iteration to have a fixedjfor each interval instance.This will give a static random interval to each item in the array.
Fiddle