-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.js
More file actions
30 lines (24 loc) · 909 Bytes
/
scripts.js
File metadata and controls
30 lines (24 loc) · 909 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
const btnStart = document.getElementById('btnStart');
const btnStop = document.getElementById('btnStop');
const btnReset = document.getElementById('btnReset');
const time = document.getElementById('timer');
let totalSeconds = 0;
time.textContent = `0 Hours 0 Minutes 0 Seconds`;
let timer;
btnStart.addEventListener("click", () => {
timer = setInterval(() => {
totalSeconds++;
const hours = Math.floor(totalSeconds / 3600);
const minutes = Math.floor((totalSeconds % 3600) / 60);
const seconds = totalSeconds % 60;
time.textContent = `${hours} Hours ${minutes} Minutes ${seconds} Seconds`;
}, 1000);
});
btnStop.addEventListener("click", () => {
clearInterval(timer);
});
btnReset.addEventListener("click", () => {
clearInterval(timer);
totalSeconds = 0;
time.textContent = `0 Hours 0 Minutes 0 Seconds`;
});