Situation:
I have X (0-20) Images that need to be shown in order with a delay between each of them.
I tried to implement that with a for-loop and setTimeout but struggle with running the innercode in synchronous order.
For example:
for(x=0;x<20;x++) {
setTimeout(doSomething(), 5000);
}
doSomething() {
setTimeout(function() {alert("test")},1000);
}
If I am not mistaken I should see an alert every 6 seconds, for 20 times. However, what happens is that after 6 seconds I see all the alerts at once (or whatever I put into doSomething)
How do I get my for-loop to wait till the innercode is completed?
setTimeout(doSomething(), (x+1) * 5000);