London | 26-ITP-May | Russom Gebremeskel | Sprint 3 | Alarm Clock App - #1375
London | 26-ITP-May | Russom Gebremeskel | Sprint 3 | Alarm Clock App#1375russom-g wants to merge 50 commits into
Conversation
… from the key and value.
…irst and catch the error.
… page refresh or 'new quote' button click
… page refresh or 'new quote' button click
…maining minutes and seconds.
… reset the timer.
This comment has been minimized.
This comment has been minimized.
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.
| let minutes = Math.floor(time / 60); | ||
| let seconds = time % 60; | ||
|
|
||
| heading.innerText = | ||
| "Time Remaining: " + | ||
| String(minutes).padStart(2, "0") + | ||
| ":" + | ||
| String(seconds).padStart(2, "0"); |
There was a problem hiding this comment.
Code on lines 18-25 is very similar to those on lines 6-13.
To adhere to the DRY principle in programming, could you refactor the repeated code into a reusable function?
There was a problem hiding this comment.
Thanks for the feedback. Good point. I implemented a new function called updateDisplay for displaying when the alarm is set first and for setInterval for displaying each second
| @@ -1,4 +1,35 @@ | |||
| function setAlarm() {} | |||
| function setAlarm() { | |||
| let time = Number(document.getElementById("alarmSet").value); | |||
There was a problem hiding this comment.
Is there any value the app should reject to ensure the app won't behave abnormally?
There was a problem hiding this comment.
Yes non number or negative number. I added an if statement for checking those invalid inputs
There was a problem hiding this comment.
I also added another if condition with clearIntervals. This is for return to a clean initial state when a new alarm is set.
Learners, PR Template
Self checklist
Changelist
A set alarm function implemented in order to the alarm clock app to take minutes and seconds input, countdown, display, play sound and reset timer when countdown to 0.