Hi I'm trying to get a for loop to run 3 times with an increasing interval each time. I'd like the loop to output text to the console each time it runs but I can't stop the loop from running all at once and showing done, finished, and done, then finished twice. Code:
function tellMeWhenDone () {
for(var i=0; i<3; i++) {
if (i === 0)
var text = console.log('done');
else if (i === 1)
var text = console.log('and done');
else (i === 2)
var text = console.log('finished');
time(i);
}
}
function time (i){
setInterval(function(text){
return text;
}, 1000*(i+1))
}
tellMeWhenDone();
Any help would be greatly appreciated! Thank you.
var text = console.log('done');? What value do you expect for text and what will you do with it? Why if..else when you can do['done','and done','finished'][i]?