-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
44 lines (36 loc) · 1.09 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
let timerInterval;
let seconds = 0;
let isRunning = false;
const display = document.getElementById('display');
const startBtn = document.getElementById('startBtn');
const resetBtn = document.getElementById('resetBtn');
function formatTime(seconds) {
const hrs = Math.floor(seconds / 3600);
const mins = Math.floor((seconds % 3600) / 60);
const secs = seconds % 60;
return `${String(hrs).padStart(2, '0')}:${String(mins).padStart(2, '0')}:${String(secs).padStart(2, '0')}`;
}
function updateDisplay() {
display.textContent = formatTime(seconds);
}
function startTimer() {
if (isRunning) return;
isRunning = true;
timerInterval = setInterval(() => {
seconds++;
updateDisplay();
}, 1000);
startBtn.disabled = true;
resetBtn.disabled = false;
}
function resetTimer() {
clearInterval(timerInterval);
isRunning = false;
seconds = 0;
updateDisplay();
startBtn.disabled = false;
resetBtn.disabled = true;
}
startBtn.addEventListener('click', startTimer);
resetBtn.addEventListener('click', resetTimer);
resetBtn.disabled = true;