Skip to content

Commit 7de5ee6

Browse files
author
Enice-Codes
committed
modified work
1 parent 9027349 commit 7de5ee6

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

‎Sprint-3/alarmclock/alarmclock.js‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
let timer = null;
22
let secondsRemaining = 0;
33

4+
const timeRemainingEl = document.getElementById("timeRemaining");
5+
const alarmSetEl = document.getElementById("alarmSet");
6+
const stopButtonEl = document.getElementById("stop");
7+
48
function formatTime(totalSeconds) {
59
const minutes = Math.floor(totalSeconds / 60);
610
const seconds = totalSeconds % 60;
711
return `${String(minutes).padStart(2, "0")}:${String(seconds).padStart(2, "0")}`;
812
}
913

1014
function updateDisplay(seconds) {
11-
document.getElementById("timeRemaining").textContent =
12-
`Time Remaining: ${formatTime(seconds)}`;
15+
timeRemainingEl.textContent = `Time Remaining: ${formatTime(seconds)}`;
1316
}
1417

1518
function setAlarm() {
@@ -18,7 +21,7 @@ function setAlarm() {
1821
timer = null;
1922
}
2023

21-
const inputValue = document.getElementById("alarmSet").value;
24+
const inputValue = alarmSetEl.value;
2225
const seconds = Number(inputValue);
2326

2427
if (
@@ -27,8 +30,7 @@ function setAlarm() {
2730
!Number.isInteger(seconds) ||
2831
seconds <= 0
2932
) {
30-
document.getElementById("timeRemaining").textContent =
31-
"Please enter a whole number greater than 0.";
33+
timeRemainingEl.textContent = "Please enter a whole number greater than 0.";
3234
return;
3335
}
3436

@@ -54,9 +56,7 @@ function stopTimer() {
5456
}
5557
}
5658

57-
document.addEventListener("DOMContentLoaded", () => {
58-
document.getElementById("stop").addEventListener("click", stopTimer);
59-
});
59+
stopButtonEl.addEventListener("click", stopTimer);
6060

6161
// DO NOT EDIT BELOW HERE
6262
var audio = new Audio("alarmsound.mp3");

0 commit comments

Comments
 (0)