-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclock.js
More file actions
59 lines (49 loc) · 1.57 KB
/
Copy pathclock.js
File metadata and controls
59 lines (49 loc) · 1.57 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
var Clock = function(hours, minutes, seconds){
this.hours = hours;
this.minutes = minutes;
this.seconds = seconds;
this.time = function(){
var newHour = this.hours;
var newMinutes = this.minutes;
var newSeconds = this.seconds;
if (newHour < 10) {
newHour = "0" + newHour;
} if (newMinutes < 10) {
newMinutes = "0" + newMinutes;
} if (newSeconds < 10) {
newSeconds = "0" + newSeconds;
}
return newHour + ":" + newMinutes+ ":" + newSeconds;
};
this.tick = function() {
this.seconds ++;
if (this.seconds > 59) {
this.minutes ++;
this.seconds = 0;
} if (this.minutes > 59) {
this.hours++;
this.minutes = 0;
} if (this.hours > 23) {
this.hours = 0;
} for (var i = 0; i < this.alarm.length; i++) {
if (this.alarm[i] === this.time()) {
console.log(this.time() + " snozze");
}
}
};
this.alarm = [];
this.addAlarm = function(alarm) {
this.alarm.push(alarm);
};
};
var time1 = new Clock(23, 11, 59);
time1.addAlarm("23:12:00");
time1.addAlarm("00:00:00");
time1.addAlarm("06:00:00");
console.log(time1.time());
time1.tick();
console.log(time1.time());
for(var i = 0; i < 86400; i++) {
time1.tick();
}
console.log(time1.time());