JSFiddle - React, Tailwind, and code Playground
by Dogbert
HTML
<div></div>
JavaScript
function Counter(o) {
var startTime = +new Date;
var interval = setInterval(() => {
var now = o.start + ((+new Date) - startTime) / 1000 * o.speed;
if (now > o.stop)
now = o.stop
o.el.innerText = Math.floor(now).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
if (now === o.stop) {
clearInterval(interval);
}
}, 30);
}
Counter({
el: document.querySelector('div'),
start: 2900000000,
stop: 9000000000,
speed: 523456789
});