-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcountdown.js
More file actions
executable file
·69 lines (60 loc) · 2.11 KB
/
countdown.js
File metadata and controls
executable file
·69 lines (60 loc) · 2.11 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
var endAlert = 60;
var startHours,
startMinutes,
startSeconds,
timer,
endTimer;
function setTime() {
var getHours = document.getElementById('hours');
var getMinutes = document.getElementById('minutes');
var getSeconds = document.getElementById('seconds');
var valHours = getHours.value;
var valMinutes = getMinutes.value;
var valSeconds = getSeconds.value;
startHours = parseInt(valHours, 10);
startMinutes = parseInt(valMinutes, 10);
startSeconds = parseInt(valSeconds, 10);
timer = setInterval(countDown, 1000)
}
function countDown() {
document.getElementById('countdown').innerHTML = startHours + ' : ' + startMinutes + ' : ' + startSeconds;
if(startSeconds === 0){
if(startMinutes === 0){
if(startHours === 0){
clearInterval(timer);
endTimer = setInterval(blinkBackground, 1000);
} else {
startHours--;
startMinutes = 60;
startSeconds = 60;
}
}else {
startMinutes--;
startSeconds = 30;
}
}else{
startSeconds--;
}
}
function blinkBackground() {
if (endAlert === 0) {
clearInterval(endTimer);
document.body.style.backgroundColor = "white";
document.getElementById('audio_file').innerHTML = ''
} else {
document.getElementById('audio_file').innerHTML = "<audio autoplay='autoplay'><source src='alarm.mp3'></audio>";
if (document.body.style.backgroundColor === "white") {
document.body.style.backgroundColor = "blue";
} else if (document.body.style.backgroundColor === "blue") {
document.body.style.backgroundColor = "green";
} else if (document.body.style.backgroundColor === "green") {
document.body.style.backgroundColor = "red";
} else if (document.body.style.backgroundColor === "red"){
document.body.style.backgroundColor = "blue";
}
endAlert--;
}
}
function cancelAlert(){
endAlert = 0;
}