-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimer.js
129 lines (94 loc) · 2.86 KB
/
timer.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
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
const hour = document.getElementById('hour');
const minute = document.getElementById('minute');
const second = document.getElementById('second');
const start = document.getElementById('start');
const reset = document.getElementById('reset');
const disp = document.getElementById('disp');
const audio = new Audio("wednesday.mp3");
var startTimer = null;
start.addEventListener('click', function(){
if(startTimer === null && (hour.value > 0 || minute.value > 0 || second.value > 0)){
startTimer = setInterval(function() {
timer();
}, 1000);
hour.disabled = true;
minute.disabled = true;
second.disabled = true;
}
});
reset.addEventListener('click',()=>{
clearInterval(startTimer);
startTimer = null;
hour.value = 0;
minute.value = 0;
second.value = 0;
disp.innerText="Timer ";
audio.pause();
});
function timer(){
if(hour.value == 0 && minute.value == 0 && second.value == 0){
hour.value = 0;
minute.value = 0;
second.value = 0;
stopInterval();
audio.play();
} else if(second.value != 0){
second.value--;
} else if(minute.value != 0 && second.value == 0){
second.value = 59;
minute.value--;
} else if(hour.value != 0 && minute.value == 0){
minute.value = 60;
hour.value--;
}
}
function stopInterval() {
clearInterval(startTimer);
startTimer = null;
hour.disabled = false;
minute.disabled = false;
second.disabled = false;
}
// 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 hr = Math.floor(total/3600);
// var mt = Math.floor((total/60) - (hr*60));
// var sc= total - ((hr*3600)+(mt*60));
// hour.value = hr;
// minute.value = mt;
// second.value = sc;
// }
// else{
// disp.innerText = "Time's Up !!";
// // If the count down is finished, play audio file
// if (disp.innerText="Time's Up !!") {
// clearInterval(interval);
// audio.play()
// }
// }
// }
// start.addEventListener('click',()=>{
// if(interval === null && (hour.value > 0 || minute.value >0 || second.ariaValueNow))
// clearInterval(interval);
// interval = setInterval(Timer,1000);
// disp.innerText = "Timer Started..";
// hour.disabled = true;
// minute.disabled = true;
// second.disabled = true;
// });
// reset.addEventListener('click',()=>{
// clearInterval(interval);
// hour.value = 0;
// minute.value = 0;
// second.value = 0;
// disp.innerText="Timer ";
// audio.pause();
// });