London | 26-ITP-Jan | Miriam Jorna | Sprint 3 | Alarmclock#1192
London | 26-ITP-Jan | Miriam Jorna | Sprint 3 | Alarmclock#1192miriamjorna wants to merge 10 commits intoCodeYourFuture:mainfrom
Conversation
This comment has been minimized.
This comment has been minimized.
2 similar comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
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 behavior between runs.
Consider introducing a dedicated reset function to return the app to a clean initial state, and call this function before starting a new countdown to help ensure consistency.
Hint: a user may not click the "Stop" button first before starting a new count down.
| if (seconds <= 0) { | ||
| alert("The number of seconds must be more than 0 please"); | ||
| return; | ||
| } |
There was a problem hiding this comment.
Indentation is off.
Have you installed the prettier VSCode extension and enabled "Format on save/paste" on VSCode,
as recommended in
https://github.com/CodeYourFuture/Module-Structuring-and-Testing-Data/blob/main/readme.md
?
If you have enabled "Format on save" but it is not working, it is likely that you haven't assign a formatter for JS file. This could happen if you have zero or multiple extensions that can format .js file.
If you have installed "Prettier" extension. To assign it as the formatter of JS code, you can try:
- Use "Format document" to format the JS file. Sometimes, VSCode will ask you to choose a formatter, and you can manually select "Prettier".
- Edit
settings.jsonand set Prettier as the default formatter for JS.
See: https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode
There was a problem hiding this comment.
Oh, my apologies, I inserted that and did not prettify it after doing so. Tbh I would normally have done that by hand quickly. Just forgot.
| let seconds = parseInt(document.getElementById("alarmSet").value); | ||
|
|
||
| if (seconds <= 0) { |
There was a problem hiding this comment.
Some invalid input can make the app behave abnormally.
Note: Why requiring min to be 0 here but set the "min" attribute in HTML to 1?
There was a problem hiding this comment.
To be honest I'm a bit puzzled by your note.
When I noticed that the little arrows on the input box could give negative values I changed the requirements to be >0 by putting in this
if (seconds <= 0)
alert("The number of seconds must be more than 0 please");
and making sure the input required integers.
It has to be minimal 1 because otherwise the clock can't start.
What am I missing that makes you state the min is 0 here? Because when it is 0 the warning comes up?
There was a problem hiding this comment.
Oh wait, a different notation would work for both things you said.
Have changed it to
(!seconds || seconds < 1)
| function updateDisplay() { | ||
| const minutes = Math.floor(seconds / 60); | ||
| const remainingSeconds = seconds % 60; | ||
| document.getElementById("timeRemaining").textContent = | ||
| `Time Remaining: ${String(minutes).padStart(2, "0")}:${String(remainingSeconds).padStart(2, "0")}`; | ||
| } |
There was a problem hiding this comment.
Would be better to design the function to take seconds through a parameter, and move the function to the outer scope.
This way, you can call updateDisplay(0) on line 7 -- keep the display logic in one place.
| audio.pause(); | ||
| document.getElementById("timeRemaining").textContent = "Time Remaining: 00:00"; | ||
| document.body.classList.toggle("alarm-activated", false); | ||
| } |
There was a problem hiding this comment.
This function is never called.
| // code to reset background | ||
| function pauseAlarm() { | ||
| audio.pause(); | ||
| document.body.classList.toggle("alarm-activated", false); | ||
| } |
There was a problem hiding this comment.
This function is also never called.
| @@ -1,4 +1,46 @@ | |||
| function setAlarm() {} | |||
| let countdown; | |||
There was a problem hiding this comment.
Consider renaming countdown to countdownInterval or intervalId since this stores the interval ID, not the countdown value.
Self checklist
Changelist
Made a working alarm clock.
The page changes colour when the alarm goes off.
I've made a colour reset provision for when the alarm is paused (=what the user perceives as turning it off).
Noticed input could be negative; have made sure only positive integers can now be used to set the time.