JSFiddle - React, Tailwind, and code Playground

by Darby Rathbone

HTML

<div id='countdown'></div>

JavaScript

var start = Date.now(),
    timedifference = 0,
    countdown = document.getElementById('countdown');
requestAnimationFrame(function anim() {
    requestAnimationFrame(anim);
    start = start || Date.now();
        countdown.innerHTML  = 10-((Date.now()-start)/1000|0);
     timedifference = (Date.now() - start) / 1000 | 0;
    if (timedifference >=10) {
        
        start = Date.now(); //resets the timer
        timedifference = 0; //not needed but probably won't hurt;
        document.body.appendChild(document.createTextNode('ten seconds have passed'));
        
        document.body.appendChild(document.createElement('br'));
    }
});