Exogenist
2/27/2018 - 11:06 PM

setTimeout error function

var counter = 0;
var err = 0;
function init() {
  var timeStart = new Date().getTime();
  var timeEnd;
  setTimeout(function () {
    if (counter <= 18) {
      counter++;
      timeEnd = new Date().getTime();
      //       console.log((timeEnd - timeStart)-100);
      err += (timeEnd - timeStart) - 100;
      init();
    } else {
      console.log(err)
    }
  }, 100);
}
init();