Skip to content

Commit ccf9c34

Browse files
committed
handle negative input
1 parent b4bde21 commit ccf9c34

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

Sprint-3/alarmclock/alarmclock.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ function updateDisplay() {
1010
}
1111

1212
function startCountdown() {
13+
if (remainingSeconds < 0) remainingSeconds = 0;
1314
timerId = setInterval(() => {
14-
1515
updateDisplay();
16+
1617
if (remainingSeconds <= 0) {
1718
remainingSeconds = 0;
1819
clearInterval(timerId);
@@ -25,14 +26,12 @@ function startCountdown() {
2526

2627
function setAlarm() {
2728
const input = document.getElementById("alarmSet");
28-
if (input.value==="")return;
29+
if (input.value === "") return;
2930
const inputValue = Number(input.value);
30-
31-
3231
clearInterval(timerId);
3332
timerId = null;
3433
remainingSeconds = inputValue;
35-
34+
3635
updateDisplay();
3736
startCountdown();
3837
input.value = "";

0 commit comments

Comments
 (0)