Glasgow | 26-ITP-May | Francesco Romano Monda | Sprint 3 | Alarm Clock App - #1370
Glasgow | 26-ITP-May | Francesco Romano Monda | Sprint 3 | Alarm Clock App#1370fromonda wants to merge 5 commits into
Conversation
cjyuan
left a comment
There was a problem hiding this comment.
Currently when starting a new countdown, the application does not always return to a clean initial state, which can lead to inconsistent behaviour between runs.
Note: a user may not click the "Stop" button first before starting a new count down.
I have fixed the Stop Alarm functionality by adding a stopAlarm() function that clears the timer and pauses the alarm. |
| document.getElementById("set").addEventListener("click", setAlarm); | ||
| document.getElementById("stop").addEventListener("click", stopAlarm); |
There was a problem hiding this comment.
The original code also assigns event listeners (on lines 61-67) to these two buttons. Could you find a way to prevent setAlarm() and pauseAlarm() from being called twice (without modifying the original code)?
There was a problem hiding this comment.
I prevented the duplicate calls by adding event listeners in the capture phase and using event.stopImmediatePropagation(). This stops the original event listeners from firing as well, so setAlarm() and pauseAlarm() are each called only once, without modifying the original code below the DO NOT EDIT section.
I hope this resolves the issue and that you can now mark the assignment as complete.
cjyuan
left a comment
There was a problem hiding this comment.
Your approach works. All good.
If time permits, do use AI to research the pros and cons of different approaches.
| setButton.addEventListener( | ||
| "click", | ||
| function (event) { | ||
| event.stopImmediatePropagation(); | ||
| setAlarm(); | ||
| }, | ||
| true | ||
| ); |
There was a problem hiding this comment.
Why not just let the original code to call setAlarm()?
| stopButton.addEventListener( | ||
| "click", | ||
| function (event) { | ||
| event.stopImmediatePropagation(); | ||
| stopAlarm(); | ||
| }, | ||
| true | ||
| ); |
There was a problem hiding this comment.
Given that the original code would call pauseAlarm(), an alternative is to add another event listener that calls only "clearInterval()", and let the original code stop the audio.
Self checklist
Changelist