JSFiddle - React, Tailwind, and code Playground

by Kevin Faulhaber

JavaScript

var loop = function(callback){
  var count = 0;
  var si = setInterval(function(){
     count++
     if(f<=10){
         clearInterval(si);   
     }
      callback(count);
   }, 1000);

};

loop(function(count){
   //callback has been called successfully and the loop has ended.
   //do stuff here
    console.log('Count is at: ' + count + ' and frequency is at ' + f);
    f--;
});

(function(){

    var f = 20;
    window.f = f;

})();