Skip to content

Commit 832f671

Browse files
Ming change for pull request
1 parent c5122f9 commit 832f671

1 file changed

Lines changed: 23 additions & 7 deletions

File tree

Sprint-3/alarmclock/alarmclock.js

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,47 @@
11
let countdown = null;
22

3+
function resetAlarm() {
4+
clearInterval(countdown);
5+
countdown = null;
6+
pauseAlarm();
7+
updateHeading(0);
8+
}
9+
310
function setAlarm() {
411
const input = document.getElementById("alarmSet");
512
let time = Number(input.value);
613

7-
const heading = document.getElementById("timeRemaining");
14+
if (isNaN(time) || time < 0) {
15+
updateHeading(0);
16+
return;
17+
}
818

9-
if (countdown) {
10-
clearInterval(countdown);
19+
resetAlarm();
20+
21+
if (time === 0) {
22+
updateHeading(0);
23+
playAlarm();
24+
return;
1125
}
1226

13-
updateHeading(time, heading);
27+
updateHeading(time);
1428

1529
countdown = setInterval(() => {
1630
time--;
1731

1832
if (time <= 0) {
19-
updateHeading(0, heading);
33+
updateHeading(0);
2034
clearInterval(countdown);
2135
playAlarm();
2236
} else {
23-
updateHeading(time, heading);
37+
updateHeading(time);
2438
}
2539
}, 1000);
2640
}
2741

28-
function updateHeading(time, heading) {
42+
function updateHeading(time) {
43+
const heading = document.getElementById("timeRemaining");
44+
2945
const minutes = Math.floor(time / 60);
3046
const seconds = time % 60;
3147

0 commit comments

Comments
 (0)