Sheffield | ITP-Jan-26 | Hayriye Saricicek | Sprint 3 | alarm clock#1113
Sheffield | ITP-Jan-26 | Hayriye Saricicek | Sprint 3 | alarm clock#1113mshayriyesaricicek wants to merge 5 commits intoCodeYourFuture:mainfrom
Conversation
cjyuan
left a comment
There was a problem hiding this comment.
-
You missed updating
index.htmlaccording to an instruction inreadme.md. -
Currently, when the input is either 0 or 1, the alarm will sound 1 second afterward (a bit inconsistent).
cjyuan
left a comment
There was a problem hiding this comment.
The app is working.
If you have time, I would suggest practice refactoring the code to reduce the amount duplicated code.
| // stops countdown amd stops audio | ||
| if (countdownIntervalId) { | ||
| clearInterval(countdownIntervalId); | ||
| countdownIntervalId = null; | ||
| } | ||
| alarmRunning = false; // mark that alarm is no longer active | ||
| alarmRinging = false; // mark that alarm sound is no longer playing | ||
| pauseAlarm(); // stop audio if it's playing | ||
|
|
||
| const timerDisplay = document.getElementById("timeRemaining"); | ||
| updateTimerDisplay(timerDisplay, 0); | ||
|
|
||
| document.getElementById("alarmSet").value = ""; // clears input field when stopped | ||
| }); |
There was a problem hiding this comment.
Why not just call resetAllStates()?
| // Prevent starting a new alarm if one is already running | ||
| if (alarmRunning) { | ||
| alert("Please press Stop before setting a new alarm."); // ensues user cannot set another alarm without stopping the current one first | ||
| return; | ||
| } | ||
| if (alarmRinging) { | ||
| resetAllStates(timerDisplay); // stop previous alarm and reset states | ||
| } |
There was a problem hiding this comment.
Could also just always call resetAllStates() without checking any flags. The logic is not quite the same but doing so can simplify the application logic (lesss amount of code).
With one function call, you can remove the codes on line 46-53, 63-66, and you probably won't need alarmRinging and alarmRunning.
| clearInterval(countdownIntervalId); // stops the countdown timer | ||
| countdownIntervalId = null; // resets timer ID | ||
|
|
||
| alarmRunning = false; // mark that alarm is no longer active | ||
| alarmRinging = true; // mark that alarm sound is currently playing | ||
|
|
||
| updateTimerDisplay(timerDisplay, 0); // shows zero time |
There was a problem hiding this comment.
Could also consider replacing this code by resetAllStates().
Even though resetAllStates() is doing more than necessary, it's ok to trade slight inefficiency for simplicity.
Self checklist
Changelist
Created function for alarmclock