-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
45 lines (38 loc) · 1.06 KB
/
script.js
File metadata and controls
45 lines (38 loc) · 1.06 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
var interval;
var hours=0;
var minutes = 0;
var seconds = 0;
function startTimer() {
interval = setInterval(updateTimer, 1000);
}
function updateTimer() {
seconds++;
if (seconds >= 60) {
seconds = 0;
minutes++;
}
if (minutes >= 60) {
minutes = 0;
hours++;
}
document.getElementById("hours").textContent = padZero(hours);
document.getElementById("minutes").textContent = padZero(minutes);
document.getElementById("seconds").textContent = padZero(seconds);
// document.getElementById("hours").innerHTML = hours;
// document.getElementById("minutes").innerHTML = minutes;
// document.getElementById("seconds").innerHTML = seconds;
}
function stopTimer() {
clearInterval(interval);
}
function resetTimer() {
hours=0;
minutes = 0;
seconds = 0;
document.getElementById("hours").textContent = "00";
document.getElementById("minutes").textContent = "00";
document.getElementById("seconds").textContent = "00";
}
function padZero(value) {
return value < 10 ? "0" + value : value;
}