JSFiddle - React, Tailwind, and code Playground

by jfriend00

HTML

Seconds Remaining: <span id="countdown"></span>

JavaScript

// This demo modified to show seconds remaining just so
// one can see it operate quicker

function showTimer(selector, seconds) {
  var startTime = Date.now();
  var interval;
  
  function showRemaining() {
    var delta = Date.now() - startTime;     // milliseconds
    var deltaSeconds = delta / (1000);
    if (deltaSeconds < seconds) {
      // display minutes remaining
      $(selector).text(Math.round(seconds - deltaSeconds));
    } else {
      $(selector).text(0);
      clearInterval(interval);
    }
  }
  
  interval = setInterval(showRemaining, 500);
  showRemaining();
}

$(document).ready(function(){
  showTimer("#countdown", 25);
});