From 735f1685ea1d62c2f934df90cfe1ee743dff1489 Mon Sep 17 00:00:00 2001 From: Boof <97455552+hexahigh@users.noreply.github.com> Date: Wed, 31 May 2023 13:43:06 +0200 Subject: [PATCH] a --- index.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 1a7cffe..ef66a8c 100644 --- a/index.js +++ b/index.js @@ -4,17 +4,26 @@ function calculateYearsSince(date) { return Math.floor(diffInYears); } +var year = 2023 const myDate = new Date('2009-06-08'); document.getElementById("age").innerText = calculateYearsSince(myDate) + " Years old"; const currentYear = new Date().getFullYear(); -const theDate = currentYear + "-06-08" +const theDate = year + "-06-08" function countdownTimer() { const now = new Date().getTime(); const nextYear = new Date(theDate).getTime(); const timeRemaining = nextYear - now; + if (nextYear < 0) { + year = year + 1 + countdownTimer() + } else { + countdown() + } +} +function countdown() { const days = Math.floor(timeRemaining / (1000 * 60 * 60 * 24)); const hours = Math.floor((timeRemaining % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); const minutes = Math.floor((timeRemaining % (1000 * 60 * 60)) / (1000 * 60)); @@ -25,4 +34,4 @@ function countdownTimer() { } // Call the countdownTimer() function every second using setInterval -setInterval(countdownTimer, 1000); \ No newline at end of file +setInterval(countdown, 1000); \ No newline at end of file