-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
34 lines (27 loc) · 1.1 KB
/
script.js
File metadata and controls
34 lines (27 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Select elements
const timerElement = document.getElementById("timer");
const previewButton = document.getElementById("preview");
// Countdown Timer Function
function startCountdown() {
const newYear = new Date("January 1, 2025 00:00:00").getTime();
setInterval(() => {
const now = new Date().getTime();
const timeLeft = newYear - now;
const days = Math.floor(timeLeft / (1000 * 60 * 60 * 24));
const hours = Math.floor((timeLeft % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
const minutes = Math.floor((timeLeft % (1000 * 60 * 60)) / (1000 * 60));
const seconds = Math.floor((timeLeft % (1000 * 60)) / 1000);
timerElement.textContent = `${days}d : ${hours}h : ${minutes}m : ${seconds}s`;
// Display "Happy New Year!" when countdown ends
if (timeLeft < 0) {
clearInterval();
timerElement.textContent = "🎉 Happy New Year! 🎉";
}
}, 1000);
}
// Preview Button Event
previewButton.addEventListener("click", () => {
alert("🎉 Happy New Year in advance! 🎉");
});
// Start the countdown on page load
startCountdown();