-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalarmClock.js
More file actions
77 lines (68 loc) · 1.56 KB
/
alarmClock.js
File metadata and controls
77 lines (68 loc) · 1.56 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
function getTime(a, b, c){
var curr = new Date();
let ch = curr.getHours();
let cm = curr.getMinutes();
let cs = curr.getSeconds();
let currTime = (ch * 3600000) + (cm * 60000) + (cs * 1000)
var almTime = (a * 3600000) + (b * 60000) + (c * 1000);
console.log("Interval =",almTime-currTime);
var itv = almTime-currTime;
var myVar = setTimeout(alarm, itv);
}
setTime()
function setTime(){
for(i=0;i<24;i++){
append(i, "hour")
};
for(i=0;i<60;i++){
append(i, "minute")
};
for(i=0;i<60;i++){
append(i, "second")
};
}
function test(){
var arr = ["hour", "minute", "second"];
var time = [];
for (i=0;i<arr.length;i++) {
var x = document.getElementById(arr[i]).selectedIndex;
var y = document.getElementById(arr[i]).options[x].text;
time.push(x);
}
var [a, b, c] = time;console.log(a,b,c);
getTime(a,b,c);
}
function alarm(){
var curr = new Date();
let ch = curr.getHours();
let cm = curr.getMinutes();
let cs = curr.getSeconds();
let reminder = document.getElementById('Reminder').value
play();
alert(reminder+"\n"+timeSyntax(ch)+":"+timeSyntax(cm)+":"+timeSyntax(cs));
if (confirm) {
pause();
}
}
var aud = document.getElementById('audio');
function play(){
aud.play();
}
function pause(){
aud.pause();
}
function timeSyntax(a){
if (a<10){
return "0"+a
}
else{
return a
}
}
function append(a, b){
var s = document.getElementById(b);
var node = document.createElement('option');
var textNode = document.createTextNode(a);
node.appendChild(textNode);
s.appendChild(node);
}