When I run the below it shows the countdown as expected and starts counting down. But when the countdown hits 0 it resets at 59:00 and my text "Expired" does not show.
I am wanting to show a countdown clock in mm:ss for the difference between "now" and "exam_end_time" timestamps. Once it completes it should full stop and the text should display.
Where the time now is 15:01:00 - The countdown time should start at 04:00
<div id="demo"></div>
<script>
var diff = document.getElementById('demo');
var now = moment.utc().format("YYYY-MM-DD HH:mm:ss");
var input_time = '2022-07-01 15:00:00';
var exam_end_time ='2022-07-01 15:05:00';
var mins = moment.utc(moment(exam_end_time, "HH:mm"),diff(moment(now, "HH:mm"))).format("mm")
var frequency = mins*60
var refreshIntervalId = setIntervan(() => {
const formatted = moment.utc(frequency--*1000.format("mm:ss");
diff.innerHTML = formatted;
}, 1000;
// When countdown hits zero. Stop the clock and show "Expired"
setTimeout(() => {
if(mins === ) {
diff.innerHTML = "Expired";
clearInterval(refreshIntervalId);
}},frequency*1000;
</script>