Skip to content

Commit fc50e53

Browse files
committed
Added error handling
1 parent 22008f8 commit fc50e53

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

Sprint-3/alarmclock/alarmclock.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ function formatTime(seconds) {
1010

1111
function setAlarm() {
1212
let seconds = parseInt(document.getElementById("alarmSet").value);
13+
if (!Number.isFinite(seconds) || seconds < 1) {
14+
throw new Error("Please enter a valid number greater than 0");
15+
}
1316
clearInterval(countdown);
1417
document.getElementById("timeRemaining").textContent =
1518
"Time Remaining: " + formatTime(seconds);
@@ -21,7 +24,7 @@ function setAlarm() {
2124

2225
if (seconds <= 0) {
2326
clearInterval(countdown);
24-
document.body.classList.add("alarm-finished")
27+
document.body.classList.add("alarm-finished");
2528
playAlarm();
2629
}
2730
}, 1000);
@@ -44,7 +47,7 @@ function playAlarm() {
4447
function pauseAlarm() {
4548
clearInterval(countdown);
4649
audio.pause();
47-
document.body.classList.remove("alarm-finished")
50+
document.body.classList.remove("alarm-finished");
4851
}
4952

5053
window.onload = setup;

0 commit comments

Comments
 (0)