How to setInterval with different time stop? I used this code if else but it's not working. I would like the 3 balls stop with different time, the first one is 100ms the 2nd one is 150ms and the 3rd one is 200ms.
var roll_balls, roll_balls;
function SetInterval() {
var balls, balls1, balls2;
var timesRun = 0;
var interval = setInterval(RollingBalls, 30 );
function RollingBalls() {
timesRun += 1;
console.log('tick tock');
if (timesRun === 100) {
console.log('done');
clearInterval(interval);
}
balls = Math.floor(Math.random() * 10);
var ballsDOM = document.querySelector('#balls-0');
ballsDOM.src = 'numbers/ball-' + balls + '.png';
else if (timesRun === 150) {
console.log('done');
clearInterval(interval);
}
balls1 = Math.floor(Math.random() * 10);
var ballsDOM1 = document.querySelector('#balls-1');
ballsDOM1.src = 'numbers/ball-' + balls1 + '.png';
else if (timesRun === 200) {
console.log('done');
clearInterval(interval);
}
balls2 = Math.floor(Math.random() * 10);
var ballsDOM2 = document.querySelector('#balls-2');
ballsDOM2.src = 'numbers/ball-' + balls2 + '.png';
}
}