Skip to content

Commit

Permalink
✨ Update script.js (again)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kan-A-Pesh authored Mar 10, 2024
1 parent b9ac46b commit 05ac441
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions script.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
// modifier heure si nécessaire
const endDate = new Date("2024-03-22T13:00:00").getTime();

const countdown = setInterval(() => {
const refreshCountdown = () => {
const now = new Date().getTime();
const distance = endDate - now;

// Reload when the timer is over
if (distance < 0) {
window.location.reload();
}

const days = Math.floor(distance / (1000 * 60 * 60 * 24));
const hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
const minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
Expand All @@ -14,11 +19,7 @@ const countdown = setInterval(() => {
document.getElementById("countdown").innerHTML += `<p>${hours}<span>H</span></p>`;
document.getElementById("countdown").innerHTML += `<p>${minutes}<span>M</span></p>`;
document.getElementById("countdown").innerHTML += `<p>${seconds}<span>S</span></p>`;
}

if (distance < 0) {
clearInterval(countdown);
document.getElementById("countdown").innerHTML ="Le countdown est terminé !";
}
}, 1000);


setInterval(refreshCountdown, 1000);
refreshCountdown();

0 comments on commit 05ac441

Please sign in to comment.