JSFiddle - React, Tailwind, and code Playground

by ian_smithz

JavaScript

function repeat(action, initial, slowdown, count, callback) {
    function next(time) {
       window.setTimeout(function() {
          
           if (count--) {
               action();
               next(time+slowdown);
           }
           else
             callback();
       }, time);
    }
 
    next(initial);
}


repeat(docWrite, 0, 250, 5000/250, function() {
    document.write("done"); 
});

function docWrite(){
     document.write("test");
}