How to stop timer after a specified time interval?

Welcome. Please tell me how to stop the timer after he lost one time (or 24 minutes)

<div class="timer">
 <span id="hours"></span>
 <span id="delimiter">:</span>
 <span id="minutes"></span>
 <span id="delimiter">:</span>
 <span id="seconds"></span>
 </div>

function updater(d, h, m, s) {

 var baseTime = Date.parse(new Date());
 // The reset period is 1 day

 var period = 1*24*60*60*1000;


 function update() {

 var cur = new Date();
 // how many milliseconds
 var diff = period + (cur - baseTime) % period;
 var diff = period + (cur - baseTime) % period;
 // how many milliseconds before the end of the second
 var millis = diff % 16.66666;
 diff = Math.floor(diff/16.66666);
 // how many seconds before the end of the minute
 var sec = diff % 60;
 if(sec < 10) sec = "0"+sec;
 diff = Math.floor(diff/60);
 // how many minutes before the end of the hour
 var min = diff % 60;
 if(min < 10) min = "0"+min;
 diff = Math.floor(diff/60);
 // how many hours till end of day
 var hours = diff % 24;
 if(hours < 10) hours = "0"+hours;
 var days = Math.floor(diff / 24);

 h.innerHTML = hours;
 m.innerHTML = min;
 s.innerHTML = sec;

 // next time it called itself, when will the current second
 setTimeout(update, millis);

}
 setTimeout(update, 0);



}



updater(document.getElementById("days"),
 document.getElementById("hours"), document.getElementById("minutes"),
 document.getElementById("seconds"));
March 23rd 20 at 18:49
1 answer
March 23rd 20 at 18:51
// next time it called itself, when will the current second
setTimeout(update, millis);

You need to write the command for this condition. For correctness I do not warrant, will not test, but something like this:
if ((diff < 1000) || (cur - baseTime > 24*60*1000)) {
 setTimeout(update, millis);
}
if ((diff < 1000) || (cur - baseTime > 24*60*1000)) {
 setTimeout(update, millis);
}


So the function setTimeout(update, millis) don't stop the timer, and updates it every second. As I understand it you need to use something like stop() - efren_Becker38 commented on March 23rd 20 at 18:54
@efren_Becker38, so if the condition is not met, the team on the next update is not received and the timer stops updating, that is stops.
stop() stops the animation, not the case. - Dee.Reynolds commented on March 23rd 20 at 18:57

Find more questions by tags JavaScript