JSFiddle - React, Tailwind, and code Playground
HTML
<div class="timer"></div>
JavaScript
var minutes = 1;
var seconds = minutes * 60;
function convertIntToTime (num) {
var mins = Math.floor(num/60);
var secs = num % 60;
var timerOutput = (mins < 10 ? "0" : "" ) + mins + ":" + (secs < 10 ? "0" : "" ) + secs;
return(timerOutput);
}
var countdown = setInterval(function() {
var current = convertIntToTime(seconds); // set the display of the time
$('.timer').html(current); // place the display time in the div
if(seconds == 0) {
clearInterval(countdown); // stop the time when there are no more seconds
}
seconds--; // subtract a second
}, 1000);