Having problem with delay | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Having problem with delay

Hi everyone, how can i make a delay for each iteration in “for loop”? I tried: for (i = 0; i < 101; i++) { setTimeout(function() { document.getElementById("test").value = i },1000) } But still not work. Can anyone help me?

30th Apr 2020, 5:59 PM
Allan Nguyễn
Allan Nguyễn - avatar
3 Answers
30th Apr 2020, 7:03 PM
visph
visph - avatar
0
Allan Nguyễn wait a few: there's a problem... I repost the code as soon as fixed ;)
30th Apr 2020, 6:51 PM
visph
visph - avatar
0
Little update on previous code (support of null or not functions callbacks wasn't completly done ^^). ... and a second version (shortened name: TimeoutLoop => TimedLoop) nestable and breakable (stop() method, 'continue' should be simply done by returning from 'iter' callback argument). https://code.sololearn.com/W1KM46A0oqiV/?ref=app It's the 3rd or 4th time I implement such generic "async" nestable loop... the simple version was quick to implement, the nestable one still is not completly obvious, even if each time I redo the job from scratch I take lesser time ^^ (I'm too lazy to write an how to use, but if someone would need, just ask in comment of the code: I could at least guide if not enough motivated to write a complete documentation -- however, I guess that exploring the 30 lines of code would be enough to understand how to use it ;))
30th Apr 2020, 9:44 PM
visph
visph - avatar