-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreloj.js
More file actions
69 lines (46 loc) · 1.27 KB
/
reloj.js
File metadata and controls
69 lines (46 loc) · 1.27 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 Clock = function(hours, minutes, seconds) {
this.hours = hours;
this.minutes = minutes;
this.seconds = seconds;
this.alarm = "";
this.time = function() {
var newHours = this.hours;
var newMinutes = this.minutes;
var newSeconds = this.seconds;
if(newHours < 10) {
newHours = "0" + this.hours;
}
if(newMinutes < 10) {
newMinutes = "0" + this.minutes;
}
if(newSeconds < 10) {
newSeconds = "0" + this.seconds;
}
return newHours + ":" + newMinutes + ":" + newSeconds;
}
this.tick = function() {
this.seconds += 1
if(this.seconds > 59) {
this.seconds = 0;
this.minutes += 1;
}
if(this.minutes > 59) {
this.minutes = 0;
this.hours += 1;
}
if(this.hours > 23) {
this.hours = 0;
}
if(this.alarm == this.time()) {
console.log(this.time() + " " + "Alarm") }
};
this.addalarm = function(alarm) {
this.alarm = alarm;
};
};
var clock = new Clock(23, 59, 59);
clock.addalarm("00:00:01") ;
console.log(clock.time());
clock.tick();
clock.tick() ;
console.log(clock.time());