-
-
Notifications
You must be signed in to change notification settings - Fork 279
London | 26-ITP-Jan | Miriam Jorna | Sprint 3 | Alarmclock #1192
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?
Changes from all commits
bc46214
724f78e
b5531bb
fa5b440
3fb860f
055596b
57ab5ca
3453a0c
459b265
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,30 @@ | ||
| function setAlarm() {} | ||
| function setAlarm() { | ||
| let seconds = parseInt(document.getElementById("alarmSet").value); | ||
|
|
||
| if (seconds <= 0) { | ||
| alert("The number of seconds must be more than 0 please"); | ||
| return; | ||
| } | ||
|
Comment on lines
+4
to
+7
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indentation is off. Have you installed the prettier VSCode extension and enabled "Format on save/paste" on VSCode, 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:
See: https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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. |
||
| 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")}`; | ||
| } | ||
|
|
||
| updateDisplay(); // update immediately on click | ||
|
|
||
| const countdown = setInterval(() => { | ||
| seconds--; | ||
| updateDisplay(); | ||
|
|
||
| if (seconds <= 0) { | ||
| clearInterval(countdown); | ||
| playAlarm(); | ||
| document.body.style.backgroundColor = "darkorange"; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To better separate presentation logic from application logic, you can consider defining a CSS class, and use
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah - this would then also remove the need to do the above recommendation on resetting the background colour, did I see that correctly? (the bit that is currently not respecting the // DO NOT EDIT BELOW HERE marker)
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can still change background color, just specify a default background color for the body element in By adding and removing the class from body, you can then switch between two background colors. Note: What you want to do (besides stopping the alarm) when the user clicks the "Stop" button is up to you. |
||
| } | ||
| }, 1000); | ||
| } | ||
|
|
||
| // DO NOT EDIT BELOW HERE | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To respect the |
||
|
|
||
|
|
@@ -20,6 +46,7 @@ function playAlarm() { | |
|
|
||
| function pauseAlarm() { | ||
| audio.pause(); | ||
| document.body.style.backgroundColor = "cornflowerblue"; | ||
| } | ||
|
|
||
| window.onload = setup; | ||
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.
Some invalid input can make the app behave abnormally.
Note: Why requiring min to be
0here but set the "min" attribute in HTML to 1?