Home › Forums › JavaScript › Need help with simple code › Reply To: Need help with simple code
September 14, 2013 at 11:14 am
#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);
}())