-
-
Notifications
You must be signed in to change notification settings - Fork 195
Manchester| 25-ITP-Sep| Fithi Teklom| Sprint 3 | Alarm Clock #908
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Sprint-3/alarmclock/alarmclock.js
Outdated
| const input = document.getElementById("alarmSet").value; | ||
| const parsed = parseInt(input, 10); | ||
|
|
||
| if (isNaN(parsed) || parsed < 0) return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should check for an empty value first. Also alert an error if any.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hello, can you please review my PR again it has been a while. step 3 has not approved because this PR is still in needs review
cjyuan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentation is a bit off. Can you improve the indentation?
Sprint-3/alarmclock/alarmclock.js
Outdated
| timer = setInterval(() => { | ||
| if (timeLeft > 0) { | ||
| timeLeft--; | ||
| updateDisplay(timeLeft); | ||
| } | ||
|
|
||
| if (timeLeft === 0) { | ||
| clearInterval(timer); | ||
| startAlarm(); | ||
| } | ||
| }, 1000); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The alarm will start 1 second after the alarm is set when the input is either 0 or 1.
That is, when the input is zero, the alarm will only start 1 second afterward (and not immediately).
Can you improve the consistency?
cjyuan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you improve the indentation of the code in this file?
VSCode has a built-in "Format document" feature that can be used to automatically indent JS code.
- Need to install "prettier" VSCode extension first.
- To auto-indent JS code, right-click in the editor and select "Format document" to format the code in the editor.
Sprint-3/alarmclock/alarmclock.js
Outdated
| clearInterval(timer); | ||
| clearInterval(flashing); // stop flashing if it was active | ||
| flashing = null; | ||
| document.body.style.backgroundColor = ""; | ||
| pauseAlarm(); // stop any playing audio | ||
| audio.currentTime = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could consider placing this "reset" code in a function and call the function here.
Sprint-3/alarmclock/alarmclock.js
Outdated
| tick(); | ||
| timer = setInterval(tick, 1000); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Considering the following two cases:
Case 1: When the input is 0 (i.e., timeLeft is 0)
Line 69 will also be executed, resulting the code on line 62-63 being executed twice.
Case 2: When the input is 1 (i.e., timeLeft is 1)
Line 68 is executed, causing the display to show "00:00" immediately (instead of showing "00:01").
But startAlarm() is only executed one second afterward.
(Ideally, the alarm could sound as soon as the display show "00:00")
Suggestion: Since 0 is such a special case, you can consider doing something like
if (timeLeft === 0) {
}
else { // Other other cases
}
cjyuan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes look good.
Self checklist