-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstopwatch.js
More file actions
32 lines (31 loc) · 870 Bytes
/
Copy pathstopwatch.js
File metadata and controls
32 lines (31 loc) · 870 Bytes
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
var stopwatch = function(stopwatchElementID){
this.running = false;
var timeElapsed = 0;
var myTimer;
var tick = function(){
timeElapsed = Math.round((timeElapsed + Number.EPSILON) * 10) / 10;
timeElapsed = (timeElapsed + 0.1);
timeElapsed = Math.round((timeElapsed + Number.EPSILON) * 10) / 10;
if(((timeElapsed * 10) % 10) == 0){
document.getElementById(stopwatchElementID).innerHTML = (timeElapsed + '.0');
}else{
document.getElementById(stopwatchElementID).innerHTML = timeElapsed;
}
}
this.start = function(){
this.running = true;
myTimer = setInterval(tick, 100);
}
this.stop = function(){
this.running = false;
clearInterval(myTimer);
}
this.reset = function(){
this.stop();
timeElapsed = 0;
document.getElementById(stopwatchElementID).innerHTML = timeElapsed;
}
this.getValue = function() {
return timeElapsed;
}
}