JSFiddle - React, Tailwind, and code Playground

HTML

<div id="a">0</div>

JavaScript

counting(40000, '', function(){console.log('done');});
function counting(num, textCountObject, done)
{
  var s = 0;
  count();
  
  var t = setInterval(function()
  {
    s += 100;
  }, 10);
  
  function count()
  {
    s++;
    display(s);
    if (s >= num)
    {
      clearInterval(t);
      display(num);
      if (done != null)
      	done();
    }
    else
    	setTimeout(count, 1);
  }
  
  function display(s)
  {
        document.querySelector('#a').innerHTML = s;
        // textCountObject.setText(s); Phaser text object used form counting
  } 
} // counting