I have read many topics about setTimeout but still i have a problem in understanding how can i implement this function to my loop.
I'll try to show you what I mean.
function RandomHit(anyArray)
{
var turechange = false;
do{
setTimeout(function(){
var random = Math.floor(Math.random()*2);
if(random===0)
{
turechange = true;
console.log(random);
}
if(random===1)
{
console.log(random);
}
}, 2000);
}while(!turechange);
}
Every time when the loop goes again, i try slow down code for a 2000 ms. But this doesn't work.
setInterval()andclearInterval()instead ofloopandsetTimeout()