I need to run a setInterva () but when trying to do it within a while cycle the setInterval() never runs. I'm a beginner in javascript so I don't know what the reason is.
The code I try to execute is the following:
var i = 0;
while(i < 5){
var c = 0;
var t = setInterval(function(){
c++;
if(c==5){
clearInterval(t);
}
},2000);
i++;
}
What is the method to create a time.sleep() within a while cycle in javascript?