Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Need help with simple code Reply To: Need help with simple code

#150081
whatsoever
Participant

Try this out :)
It is the same code, you just have to wrap an IIAF around it.

(function () {
    var i = 0;
    function logNum () {
        i++;
        console.log(i)
    };

    var timerId = setTimeout(function loop() {
          logNum();
          timerId = setTimeout( loop, 100 );
          if ( i === 20 ) clearTimeout( timerId );
        }, 100);
}())