Skip to content

Commit 35d1734

Browse files
authored
Refactor setAlarm function for better time handling
Refactor alarm time parsing to use parseInt and clean up code.
1 parent 2e2d451 commit 35d1734

1 file changed

Lines changed: 4 additions & 13 deletions

File tree

‎Sprint-3/alarmclock/alarmclock.js‎

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,16 @@
1-
let interval;
2-
31
function displayTime(time) {
42
const remainingElement = document.getElementById("timeRemaining");
53
const minutes = String(Math.floor(time / 60)).padStart(2, "0");
64
const seconds = String(time % 60).padStart(2, "0");
75
remainingElement.innerText = `Time Remaining: ${minutes}:${seconds}`;
86
}
97

8+
let interval;
9+
1010
function setAlarm() {
11-
let time = Number(document.getElementById("alarmSet").value);
12-
13-
if (isNaN(time) || time <= 0) {
14-
return;
15-
}
16-
17-
clearInterval(interval);
18-
pauseAlarm();
11+
let time = parseInt(document.getElementById("alarmSet").value);
1912

20-
if (!Number.isInteger(time) || time <= 0) {
21-
return;
22-
}
13+
clearInterval(interval);
2314

2415
displayTime(time);
2516

0 commit comments

Comments
 (0)