-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreloj.js
More file actions
66 lines (57 loc) · 1.48 KB
/
Copy pathreloj.js
File metadata and controls
66 lines (57 loc) · 1.48 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
var Clock = function(hours, minutes, seconds){
this.hours = hours;
this.minutes = minutes;
this.seconds = seconds;
this.alarm = "";
this.time = function(){
var newHour = hours;
var newMinute = minutes;
var newSecond = seconds;
if(this.hours < 10){
newHour = ( "0" + this.hours);
} else {
newHour = this.hours;
}
if(this.minutes < 10){
newMinute = ( "0" + this.minutes);
} else {
newMinute = this.minutes;
}
if(this.seconds < 10){
newSecond = ("0" + this.seconds);
} else {
newSecond = this.seconds;
}
return newHour + ":" + newMinute + ":" + newSecond;
};
this.tick = function(){
this.seconds++;
if(this.seconds > 59){
this.seconds = 0;
this.minutes++;
}
if(this.minutes > 59){
this.minutes = 0;
this.hours++;
}
if(this.hours > 23){
this.hours = 0;
}
if(this.alarm == this.time()){
console.log(this.time() + " " + "¡Alarma!");
}
};
this.addAlarm = function(alarm) {
this.alarm = alarm;
};
};
var clock = new Clock(06,59,59);
clock.addAlarm("07:00:00");
console.log(clock.time());
clock.tick();
console.log(clock.time());
var clock = new Clock(06,59,59);
clock.addAlarm("07:00:00");
console.log(clock.time());
clock.tick();
console.log(clock.time());