-
Notifications
You must be signed in to change notification settings - Fork 0
/
Step 2 Files.js
25 lines (21 loc) · 965 Bytes
/
Step 2 Files.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
class Timer {
updateTime() {
// Calculate how much time has passed since the timer started
this.elapsedTime = Date.now() - this.startTime;
// Convert elapsed time (milliseconds) into seconds, minutes, and hours
const seconds = Math.floor((this.elapsedTime / 1000) % 60);
const minutes = Math.floor((this.elapsedTime / (1000 * 60)) % 60);
const hours = Math.floor((this.elapsedTime / (1000 * 60 * 60)) % 24);
// Display the updated time on the webpage
this.displayTime(hours, minutes, seconds);
}
displayTime(hours, minutes, seconds) {
// Display formatted time on the webpage
document.getElementById("timerDisplay").innerText =
`${this.pad(hours)}:${this.pad(minutes)}:${this.pad(seconds)}`;
}
pad(number) {
// Ensure double digits (e.g. 09 instead of 9)
return number < 10 ? '0' + number : number;
}
}