-
Notifications
You must be signed in to change notification settings - Fork 1
/
timer.js
43 lines (35 loc) · 905 Bytes
/
timer.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
var timers = [];
function addTimer(time){
timers.push(makeTimer(time);
}
var timer = {
var time;
this.timer = function(time){
this.time=time;
}
this.initializeClock = function(id){
var timer = document.getElementById(id);
updateClock();
var timeinterval = setInterval(updateClock(deadline), 1000);
}
this.getTimeRemaining = function(endtime){
var t = Date.parse(endtime) - Date.parse(new Date());
var seconds = Math.floor( (t/1000) % 60 );
var minutes = Math.floor( (t/1000/60) % 60 );
return {
'total': t,
'minutes': minutes,
'seconds': seconds
};
}
this.updateClock = function(deadline){
var t = getTimeRemaining(deadline);
clock.innerHTML = 'minutes: ' + t.minutes + '<br>' + 'seconds: ' + t.seconds;
if(t.total<=0){
clearInterval(timeinterval);
}
}
this.printTo = function(){
return this.time;
}
}