JSFiddle - React, Tailwind, and code Playground

by Matt Hopkins

HTML

<input type="text" id="txt" />
<input type="button" value="Start Timer" onclick="startTimer()" />

JavaScript

var Timer = 120;
var checkTimer = false;
var t;

function countDown() {
  document.getElementById("txt").value = Timer;
  if (Timer > 0){
  	Timer--;
  }
  t = setTimeout("countDown();", 1000);
}

function startTimer() {
  if (!checkTimer) {
    checkTimer = true;
    countDown();
  } else {
    console.log("Error!");
  }
}