JSFiddle - React, Tailwind, and code Playground

by chrisbenseler

HTML

<span></span>

JavaScript

function counter() {
    var totalSeconds = 10;
    
    function update() {
        printTime()
       setTimeout(function() {
            totalSeconds--;
           
           if(totalSeconds>-1) {
                update();
           }
        }, 1000); 
    };
    
    update();
    
    function printTime() {
        
        var min = parseInt(totalSeconds/60);
        var seg = totalSeconds%60;
        if(seg <=9){
            seg = "0"+seg;
        }
        
        $("span").html(min + ":" + seg);
        
    }
    
}

counter();