-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSW.js
More file actions
40 lines (35 loc) · 1.01 KB
/
SW.js
File metadata and controls
40 lines (35 loc) · 1.01 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
let intervalId;
let hours = 0, minutes = 0, seconds = 0;
document.getElementById("startBtn").addEventListener("click", startTimer);
document.getElementById("stopBtn").addEventListener("click", stopTimer);
document.getElementById("resetBtn").addEventListener("click", resetTimer);
function updateDisplay() {
document.getElementById("hours").innerText = String(hours).padStart(2, '0');
document.getElementById("minutes").innerText = String(minutes).padStart(2, '0');
document.getElementById("seconds").innerText = String(seconds).padStart(2, '0');
}
function startTimer() {
if (intervalId) return;
intervalId = setInterval(() => {
seconds++;
if (seconds === 60) {
seconds = 0;
minutes++;
}
if (minutes === 60) {
minutes = 0;
hours++;
}
updateDisplay();
}, 1000);
}
function stopTimer() {
clearInterval(intervalId);
intervalId = null;
}
function resetTimer() {
clearInterval(intervalId);
intervalId = null;
hours = minutes = seconds = 0;
updateDisplay();
}