-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimer.js
More file actions
50 lines (43 loc) · 1.17 KB
/
Timer.js
File metadata and controls
50 lines (43 loc) · 1.17 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
46
47
48
49
50
class Timer {
constructor() {
this.timerDuration = 0;
this.timerInterval = null;
this.isRunning = false;
this.timerName = '';
this.sound = new Audio('path/to/sound.mp3'); // Replace with actual sound file path
}
setTimer(duration, name) {
this.timerDuration = duration;
this.timerName = name;
this.displayTimerSettings();
}
startTimer() {
if (this.isRunning) return;
this.isRunning = true;
this.timerInterval = setInterval(() => {
if (this.timerDuration > 0) {
this.timerDuration--;
this.updateDisplay();
} else {
this.stopTimer();
this.sound.play();
}
}, 1000);
}
pauseTimer() {
this.isRunning = false;
clearInterval(this.timerInterval);
}
resetTimer() {
this.pauseTimer();
this.timerDuration = 0;
this.updateDisplay();
}
displayTimerSettings() {
// Logic to display timer settings on the UI
}
updateDisplay() {
// Logic to update the timer display on the UI
}
}
export default Timer;