JSFiddle - React, Tailwind, and code Playground
by Rajesh Dixit
HTML
<span id="timer"></span>
<form id="difficultyForm"></form>
JavaScript
(function () {
var totalsec = 10;
var interval = null;
function CheckTime() {
document.getElementById("timer").innerHTML = "Time left: " + parseInt(totalsec / 60) + " min " + (totalsec % 60) + " sec ";
if (totalsec <= 0) {
window.clearInterval(interval)
document.getElementById("difficultyForm").submit();
} else {
totalsec--;
}
}
function initInterval() {
interval = setInterval(function () {
CheckTime()
}, 1000);
}
initInterval();
})()