This commit is contained in:
Boof 2023-05-19 12:26:16 +02:00 committed by GitHub
parent b63c362955
commit 83dd231823
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 2 deletions

View File

@ -10,6 +10,8 @@
</head>
<body>
<p>If you were born on the 8th of June 2009 you would be</p>
<p><h3 id="age"></h3><p>Years old</p></p>
<h3 id="age"></h3>
<p>And you birthday would be in</p>
<div id="countdown"></div>
</body>
</html>

View File

@ -5,4 +5,22 @@ function calculateYearsSince(date) {
}
const myDate = new Date('2009-08-06');
document.getElementById("age").innerText = calculateYearsSince(myDate);
document.getElementById("age").innerText = calculateYearsSince(myDate) + " Years old";
function countdownTimer() {
const now = new Date().getTime();
const nextYear = new Date("2023-06-08").getTime();
const timeRemaining = nextYear - now;
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));
const seconds = Math.floor((timeRemaining % (1000 * 60)) / 1000);
const countdownDiv = document.getElementById("countdown");
countdownDiv.innerHTML = days + " days, " + hours + " hours, " + minutes + " minutes, " + seconds + " seconds";
}
// Call the countdownTimer() function every second using setInterval
setInterval(countdownTimer, 1000);