JSFiddle - React, Tailwind, and code Playground

by haluk karamete

HTML

<body>
    <div>Time Left: <span id="time">_____</span></div>
</body>

JavaScript

function startTimer(duration, display) {
    var timer = duration, minutes, seconds;
    setInterval(function () {
        minutes = parseInt(timer / 60, 10)
        seconds = parseInt(timer % 60, 10);

        minutes = minutes < 10 ? "0" + minutes : minutes;
        seconds = seconds < 10 ? "0" + seconds : seconds;

        display.text(minutes + ":" + seconds);

        if (--timer < 0) {
            timer = duration;
        }
    }, 1000);
}


jQuery(function ($) {
    
    var time_left_in_seconds = get_time_left_in_seconds();
        
    display = $('#time');
    startTimer(time_left_in_seconds, display);
});


function get_time_left_in_seconds(){

    // all the work wil go in here! 
    
    //here, we idetify the next prayer
    //then compute  the number of seconds between now and that time
    //and return the diff in seconds... 
    
    return 60;
}