I want to make a cooldown that when I reach the end of, for example, 24h, I add 1 day and start the 24h countdown again. If someone could help me, I would be very grateful, thanks in advance. Here's something I've been trying to do:
var countDownYear = new Date().getFullYear();
var countDownMonth = new Date().getMonth() + 1;
var countDownDay = new Date().getDate();
var countDownDate = new Date(countDownMonth + " " + countDownDay + ", " + countDownYear + " 15:27:30").getTime();
var x = setInterval(function () {
var now = new Date().getTime();
var distance = countDownDate - now;
var days = Math.floor(distance / (1000 * 60 * 60 * 24));
var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((distance % (1000 * 60)) / 1000);
document.querySelector('#daily-time').innerHTML = days + "d " + hours + "h " +
minutes + "m " + seconds + "s";
if (distance < 0) {
console.log(countDownDay);
countDownDay++;
console.log(countDownDay);
clearInterval(x);
}
}, 1000);
<div id="daily-time"></div>