-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathstopwatch.html
More file actions
149 lines (127 loc) · 4.11 KB
/
stopwatch.html
File metadata and controls
149 lines (127 loc) · 4.11 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// CHeck its working - http://global-solutions.me/js-stopwatch/
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>STOPWATCH</title>
<style>
body {
background: #005566;
text-align: center;
}
h1 {
font-size: 25px;
}
p {
height: 20px;
font-size: 1.5em;
}
button {
border-radius: 100%;
cursor: pointer;
width: 80px;
height: 40px;
margin: 10px;
font-size: 1.2em;
}
button:hover {
background: green;
border: solid 1px blue;
color: pink;
}
#design {
border-radius: 0%;
width: 400px;
height: 200px;
border: 10px solid rgb(23, 7, 53);
}
#design:hover {
background: brown;
border-radius: 50%;
border: solid 10px yellowgreen;
color: pink;
}
</style>
</head>
<body>
<div id="design">
<h1>STOPWATCH</h1>
<div>
<p><span id="hours">00</span>:<span id="minutes">00</span>:<span id="seconds">00</span>:<span id="tens">00</span></p>
</div>
<button id="button-start">Start</button>
<button id="button-stop">Stop</button>
<button id="button-reset">Reset</button>
</div>
<script>
window.onload = function () {
var hours = 00;
var minutes = 00;
var seconds = 00;
var tens = 00;
var appendTens = document.getElementById("tens")
var appendSeconds = document.getElementById("seconds")
var appendMinutes = document.getElementById("minutes")
var appendHours = document.getElementById("hours")
var buttonStart = document.getElementById('button-start');
var buttonStop = document.getElementById('button-stop');
var buttonReset = document.getElementById('button-reset');
var Interval;
buttonStart.onclick = function () {
clearInterval(Interval);
Interval = setInterval(startTimer, 10);
}
buttonStop.onclick = function () {
clearInterval(Interval);
}
buttonReset.onclick = function () {
clearInterval(Interval);
tens = "00";
seconds = "00";
minutes = "00";
appendTens.innerHTML = tens;
appendSeconds.innerHTML = seconds;
appendMinutes.innerHTML = minutes;
}
function startTimer() {
tens++;
if (tens <= 9) {
appendTens.innerHTML = "0" + tens;
}
if (tens > 9) {
appendTens.innerHTML = tens;
}
if (tens > 10) {
console.log("seconds");
seconds++;
appendSeconds.innerHTML = "0" + seconds;
tens = 0;
appendTens.innerHTML = "0" + 0;
}
if (seconds > 9) {
appendSeconds.innerHTML = seconds;
}
if(seconds > 59){
console.log("minutes");
minutes++;
appendMinutes.innerHTML = "0" + minutes;
seconds = 0;
appendSeconds.innerHTML = "0" + 0;
}
if(minutes > 59){
console.log("hours");
hours++;
appendHours.innerHTML = "0" + hours;
minutes = 0;
appendMinutes.innerHTML = "0" + 0;
}
if(minutes > 9){
appendMinutes.innerHTML = minutes;
}
}
}
</script>
</body>
</html>