Skip to content

Commit e8b42aa

Browse files
committed
Add funtionalities
1 parent 14af187 commit e8b42aa

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

Source-Code/CountdownTimer/script.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
document.addEventListener('DOMContentLoaded', () => {
2+
const daysEl = document.getElementById('days');
3+
const hoursEl = document.getElementById('hours');
4+
const minsEl = document.getElementById('mins');
5+
const secondsEl = document.getElementById('seconds');
6+
7+
const eid = '30 Mar 2025';
8+
const formatTime = (time) => (time < 10 ? `0${time}` : time);
9+
const countdown = () => {
10+
const EidDate = new Date(eid);
11+
const currentDate = new Date();
12+
13+
const totalSeconds = (EidDate - currentDate) / 1000;
14+
15+
const days = Math.floor(totalSeconds / 3600 / 24);
16+
const hours = Math.floor(totalSeconds / 3600) % 24;
17+
const mins = Math.floor(totalSeconds / 60) % 60;
18+
const seconds = Math.floor(totalSeconds) % 60;
19+
20+
daysEl.innerHTML = days;
21+
hoursEl.innerHTML = formatTime(hours);
22+
minsEl.innerHTML = formatTime(mins);
23+
secondsEl.innerHTML = formatTime(seconds);
24+
};
25+
26+
// initial call
27+
countdown();
28+
29+
setInterval(countdown, 1000);
30+
});

0 commit comments

Comments
 (0)