JSFiddle - React, Tailwind, and code Playground

HTML

<span id="count">5</span> seconds

<a href="#" id="startClock">Start Clock</a>

JavaScript

function startTimer(){
  var counter = 5;
  setInterval(function() {
    counter--;
    if (counter >= 0) {
      span = document.getElementById("count");
      span.innerHTML = counter;
    }
    if (counter === 0) {
        alert('sorry, out of time');
        clearInterval(counter);
    }
  }, 1000);
}
$("#startClock").click(function(){
    startTimer();
 });