Skip to content

Commit 43d79e5

Browse files
committed
stop now pawses the clock and returns the value left to the input felied the start and stop buttons are now fully hidden when not needed
1 parent 1e600fa commit 43d79e5

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

Sprint-3/alarmclock/alarmclock.js

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
botton = document.getElementById("set");
1+
const startButton = document.getElementById("set");
2+
const pause = document.getElementById("stop");
3+
pause.hidden = true;
24
//begins the count down
3-
botton.addEventListener("click", setAlarm);
45

56
// document.getElementById("set").addEventListener("click", setAlarm);
67
const timeRemaining = document.getElementById("timeRemaining");
78
function setAlarm() {
89
// gets the value of the input field and stores it in a variable
910
let timeInSeconds = document.getElementById("alarmSet").value;
10-
botton.disabled = true;
11-
1211
let clock = setInterval(() => {
1312
function pad(num) {
1413
return num.toString().padStart(2, "0");
@@ -22,16 +21,27 @@ function setAlarm() {
2221

2322
return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`;
2423
}
25-
26-
timeInSecond = timeInSeconds--;
27-
if (timeInSeconds == 0) {
24+
startButton.hidden = true;
25+
pause.hidden = false;
26+
timeInSeconds--;
27+
if (timeInSeconds <= 0) {
2828
clearInterval(clock);
2929
playAlarm();
30-
botton.disabled = false;
3130
}
31+
3232
timeRemaining.innerHTML =
3333
"time remaining " + formatTimeDisplay(timeInSeconds);
3434
}, 1000);
35+
startButton.addEventListener("click", setAlarm);
36+
pause.addEventListener("click", pauseWhenRunning);
37+
38+
function pauseWhenRunning() {
39+
startButton.hidden = false;
40+
pause.hidden = true;
41+
clearInterval(clock);
42+
document.getElementById("alarmSet").value = timeInSeconds;
43+
audio.pause();
44+
}
3545
}
3646

3747
// DO NOT EDIT BELOW HERE

0 commit comments

Comments
 (0)