Javascript - display incrementing number every second -
I'm trying to do something where I display different numbers in every second, but I set Interwolle can not be found right.
What I have here
function counters () {var i = 0; While (i & lt; 100) {// this block will be executed 100 times SetInterval (console.log ('currently' + i), 1000); I ++; // increment i}} // and but what I get is console.log firing 100 times, then repeats.
Thanks for all help
Mike
when Once you create a set interval, it will call the function automatically (the first argument) each 1000 milliseconds (second argument). So you do not have to do this inside, just increase the i inside the function. (The first argument). function counter () {var i = 0; // This block will be executed 100 times. SetInterval (function () {if (i == 100) clear interval (this); other console.log ('currently' + (i ++));}, 1000); } // End
Update 1 function counter () {var i = 0; Var funcNameHere = function () {if (i == 100) clear interval (this); Else console.log ('Currently' + (i ++)); }; // This block will be executed 100 times. Set internwall (out of Fanaknam, 7000); FuncNameHere (); } // termination
Comments
Post a Comment