London | 26-ITP-May | Edina Kurdi | Sprint 3 | Alarm clock - #1430
London | 26-ITP-May | Edina Kurdi | Sprint 3 | Alarm clock#1430edinakurdi wants to merge 10 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.
| const minutes = String(Math.floor(remainingSeconds / 60)).padStart(2, "0"); | ||
| const seconds = String(remainingSeconds - minutes * 60).padStart(2, "0"); | ||
| timeRemaining.textContent = `Time Remaining: ${minutes}:${seconds}`; |
There was a problem hiding this comment.
Code on lines 7-10 is very similar to those on lines 14-16.
To adhere to the DRY principle in programming, could you refactor the repeated code into a reusable function?
| const timeInput = document.getElementById("alarmSet"); | ||
| // console.log(timeInput.value); | ||
| let remainingSeconds = timeInput.value; |
There was a problem hiding this comment.
-
Using raw input without proper validation is a dangerous practice. For number, we should consider
- What type of number should it be? Integer or floating point number?
- What range of numbers are acceptable?
- What kind of invalid value should also be rejected?
-
Unused code and comments should be removed to keep the code clean.
There was a problem hiding this comment.
Thank you for pointing this out.
Code is updated accordingly.
…mbers and empty strings
| const seconds = String(remainingSeconds - minutes * 60).padStart(2, "0"); | ||
|
|
||
| timeRemaining.textContent = `Time Remaining: ${minutes}:${seconds}`; | ||
| timeRemaining.textContent = `Time Remaining: ${timeConvert(remainingSeconds)}`; |
There was a problem hiding this comment.
Could also consider turning this statement into a function:
- Same code is used on line 27
displayTime(remainingSeconds)is probably more readable
Learners, PR Template
Self checklist
Changelist