-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstopwatch.html
More file actions
72 lines (63 loc) · 1.55 KB
/
stopwatch.html
File metadata and controls
72 lines (63 loc) · 1.55 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
<!DOCTYPE html>
<html>
<head>
<title>Stopwatch</title>
<style>
body {
text-align: center;
font-family: Arial;
margin-top: 50px;
}
#display {
font-size: 40px;
margin-bottom: 20px;
}
button {
padding: 10px 20px;
margin: 5px;
font-size: 16px;
}
</style>
</head>
<body>
<h2>STOPWATCH</h2>
<div id="display">00:00:00</div>
<button onclick="start()">START</button>
<button onclick="pause()">PAUSE</button>
<button onclick="reset()">RESET</button>
<script>
let hours = 0, minutes = 0, seconds = 0;
let timer = null;
function updateDisplay() {
document.getElementById("display").innerHTML =
String(hours).padStart(2, '0') + ":" +
String(minutes).padStart(2, '0') + ":" +
String(seconds).padStart(2, '0');
}
function start() {
if (timer !== null) return;
timer = setInterval(() => {
seconds++;
if (seconds === 60) {
seconds = 0;
minutes++;
}
if (minutes === 60) {
minutes = 0;
hours++;
}
updateDisplay();
}, 1000);
}
function pause() {
clearInterval(timer);
timer = null;
}
function reset() {
pause();
hours = minutes = seconds = 0;
updateDisplay();
}
</script>
</body>
</html>