-
Notifications
You must be signed in to change notification settings - Fork 0
/
Script.js
78 lines (63 loc) · 1.61 KB
/
Script.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
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
70
71
72
73
74
75
76
77
78
var hr= 0;
var min=0;
var sec=0;
var count=0;
var timer= false;
function start(){
timer = true;
stopwatch();
}
function stop(){
timer= false;
stopwatch();
}
function reset(){
timer= false;
hr=0;
min=0;
sec=0;
count=0;
document.getElementById("hr").innerHTML="00";
document.getElementById("min").innerHTML="00";
document.getElementById("sec").innerHTML="00";
document.getElementById("count").innerHTML="00";
}
function stopwatch(){
if(timer == true){
count=count+1;
if (count == 100){
sec= sec+1;
count=0;
}
if (sec == 60){
min= min+1;
sec=0;
}
if (min == 60){
hr= hr+1;
min=0;
sec=0;
}
var hrString =hr;
var minString = min;
var secString =sec;
var countString = count;
if(hr<10){
hrString = "0" + hrString;
}
if(min<10){
minString = "0" + minString;
}
if(sec<10){
secString = "0" + secString;
}
if(count<10){
countString = "0" + countString;
}
document.getElementById("hr").innerHTML = hrString;
document.getElementById("min").innerHTML = minString;
document.getElementById("sec").innerHTML = secString;
document.getElementById("count").innerHTML = countString;
setTimeout("stopwatch()",10);
}
}