-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer.js
More file actions
92 lines (64 loc) · 1.9 KB
/
timer.js
File metadata and controls
92 lines (64 loc) · 1.9 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
const mainmenu = document.querySelector(".mainmenu");
const closemenu = document.querySelector(".closemenu");
const openmenu = document.querySelector(".openmenu");
openmenu.addEventListener("click", show);
closemenu.addEventListener("click", close);
function show() {
mainmenu.style.display = 'flex';
mainmenu.style.top = '0';
}
function close() {
mainmenu.style.top = '-100%';
}
const hour = document.getElementById("hour");
const minute = document.getElementById("minute");
const second = document.getElementById("second");
const start = document.getElementById('start');
const stop = document.getElementById('stop');
const reset = document.getElementById('reset');
const song = document.getElementById('song');
const disp = document.getElementById('disp');
var interval = null;
var total = 0;
totalValue = () => {
total = Number(hour.value) * 3600 + Number(minute.value) * 60 + Number(second.value);
}
Timer = () => {
totalValue();
total--;
if (total >= 0) {
var hrs = Math.floor(total / 3600);
var min = Math.floor((total / 60) - (hrs * 60));
var sec = total - ((hrs * 3600) + (min * 60));
hour.value = hrs;
minute.value = min;
second.value = sec;
}
else {
disp.innerText = "Time's Up !";
playSong();
}
}
start.addEventListener('click', () => {
clearInterval(interval);
interval = setInterval(Timer, 1000);
disp.innerText = "Timer Started";
})
stop.addEventListener('click', () => {
clearInterval(interval);
stopSong();
})
reset.addEventListener('click', () => {
clearInterval(interval);
hour.value = 0;
minute.value = 0;
second.value = 0;
disp.innerText = "Timer";
})
function playSong() {
song.play();
}
function stopSong() {
song.pause();
song.currentTime = 0;
}