setInterval in JavaScript | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

setInterval in JavaScript

Guys, any help on how to time the interval of display in JavaScript? Eg. If i input 5 into my textbox and i submit, it displays 5 cans of coke ALL AT ONCE. How do i get it to show a can every 2 seconds till all 5 are displayed ?

4th Feb 2018, 6:15 PM
Nana Boafo Yeboah
Nana Boafo Yeboah - avatar
3 Answers
+ 6
4th Feb 2018, 7:35 PM
Burey
Burey - avatar
+ 5
here's Burey's code with setTimeout variation https://code.sololearn.com/WU8Dw46c6gOz/?ref=app
4th Feb 2018, 8:14 PM
Morpheus
Morpheus - avatar
+ 4
could use either setInterval: setInterval (function (){ //Ur task here }, 2000); or can use setTimeout , with delay for each task : setTimeout ( function (){ // Ur task here }, 2000);
4th Feb 2018, 8:02 PM
Morpheus
Morpheus - avatar