forked from dhairyagothi/100_days_100_web_project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
51 lines (39 loc) · 1.6 KB
/
index.js
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
setInterval(() => {
d = new Date();
htime = d.getHours();
mtime = d.getMinutes();
stime = d.getSeconds();
hrotation = 30 * htime + mtime / 2;
mrotation = 6 * mtime;
srotation = 6 * stime;
hour.style.transform = `rotate(${hrotation}deg)`;
minute.style.transform = `rotate(${mrotation}deg)`;
second.style.transform = `rotate(${srotation}deg)`;
}, 1000);
// Countdown Timer
let countdownInterval;
let countdownTime;
function startCountdown() {
let hours = document.getElementById('hours').value || 0;
let minutes = document.getElementById('minutes').value || 0;
let seconds = document.getElementById('seconds').value || 0;
countdownTime = (hours * 3600) + (minutes * 60) + seconds;
clearInterval(countdownInterval); // Clear any previous countdowns
countdownInterval = setInterval(() => {
if (countdownTime <= 0) {
clearInterval(countdownInterval);
//show pop up msg
document.getElementById('timerUpMsg').style.display = 'block';
// Play alarm sound
const timerSound = document.getElementById('timerSound');
timerSound.play();
} else {
countdownTime--;
let hoursLeft = Math.floor(countdownTime / 3600);
let minutesLeft = Math.floor((countdownTime % 3600) / 60);
let secondsLeft = countdownTime % 60;
document.getElementById('countdownDisplay').textContent =
`${String(hoursLeft).padStart(2, '0')}:${String(minutesLeft).padStart(2, '0')}:${String(secondsLeft).padStart(2, '0')}`;
}
}, 1000);
}