-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclock.js
65 lines (55 loc) · 1.67 KB
/
clock.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
var Clock=function(HH, MM, SS){
this.HH=HH;
this.MM=MM;
this.SS=SS;
this.time = function(){
var NewHH=this.HH;
var NewMM=this.MM;
var NewSS=this.SS;
if (this.HH <10){
NewHH="0"+this.HH}
if (this.MM <10){
NewMM ="0"+this.MM}
if (this.SS <10){
NewSS="0"+this.SS}
return NewHH+":"+NewMM+":"+ NewSS;
};
this.tick=function(){
this.SS++;
if (this.SS>=60){
this.SS=0;
this.MM++;
}
if (this.MM>=60){
this.MM=0;
this.HH++;
}
if (this.HH>=24){
this.HH=0;
}
if (this.time () == this.alarm){
console.log("alert");
}
};
this.alarm = [];
this.addAlarm=function(alarm){
this.alarm.push(alarm);
};
};
var hour1=new Clock(20, 59, 58);
hour1.addAlarm("21:00:02");
console.log(hour1.time());
hour1.tick();
console.log(hour1.time());
hour1.tick();
console.log(hour1.time());
hour1.tick();
console.log(hour1.time());
hour1.tick();
console.log(hour1.time());
hour1.tick();
console.log(hour1.time());
hour1.tick();
console.log(hour1.time());
hour1.tick();
console.log(hour1.time());