Skip to content

Commit 33c4e01

Browse files
Returned to a clean state always and fixed invalid numbers
1 parent 3a14a0e commit 33c4e01

1 file changed

Lines changed: 16 additions & 14 deletions

File tree

‎Sprint-3/alarmclock/alarmclock.js‎

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,34 +14,36 @@ let timer;
1414
function setAlarm() {
1515
clearInterval(timer);
1616
pauseAlarm();
17-
let totalSeconds = Number(alarmInput.value);
18-
alarmInput.value = "";
17+
let totalSeconds = Math.round(Number(alarmInput.value));
18+
1919
if (totalSeconds > 36000) {
2020
alert("Please enter a time less than 10 hours.");
21+
updateTime(0);
2122
return;
2223
}
23-
if (totalSeconds <= 0 || !Number.isInteger(totalSeconds)) {
24+
if (alarmInput.value === "" || totalSeconds < 0 || !Number.isInteger(0)) {
2425
alert("Please enter a valid positive time.");
26+
updateTime(0);
2527
return;
2628
}
27-
function updateTime() {
28-
const minutes = String(Math.floor(totalSeconds / 60)).padStart(2, "0");
29-
const seconds = String(totalSeconds % 60).padStart(2, "0");
30-
31-
timeRemaining.innerText = `Time Remaining: ${minutes}:${seconds}`;
32-
}
33-
updateTime();
29+
alarmInput.value = "";
30+
updateTime(totalSeconds);
3431

3532
timer = setInterval(() => {
36-
totalSeconds--;
37-
updateTime();
38-
39-
if (totalSeconds === 0) {
33+
if (totalSeconds <= 0) {
4034
clearInterval(timer);
4135
playAlarm();
4236
}
37+
updateTime(totalSeconds--);
4338
}, 1000);
4439
}
40+
41+
function updateTime(secs) {
42+
const minutes = String(Math.floor(secs / 60)).padStart(2, "0");
43+
const seconds = String(secs % 60).padStart(2, "0");
44+
45+
timeRemaining.innerText = `Time Remaining: ${minutes}:${seconds}`;
46+
}
4547
// DO NOT EDIT BELOW HERE
4648

4749
var audio = new Audio("alarmsound.mp3");

0 commit comments

Comments
 (0)