-
-
Notifications
You must be signed in to change notification settings - Fork 283
London | 26-ITP-Jan | Angela McLeary | Sprint 3 | Alarm clock app #1134
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 9 commits
ae8ac1f
8cd966d
473b4a4
b2436d3
9ddf206
dbc914a
0146e8d
3ef2c65
6fcbfc7
843f431
3894cc5
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,80 @@ | ||
| function setAlarm() {} | ||
| let alarmInterval; | ||
| let colorInterval; | ||
|
|
||
| function setAlarm() { | ||
| clearInterval(alarmInterval); | ||
| const timeRemaining = document.querySelector("#alarmSet"); | ||
| const display = document.querySelector("#timeRemaining"); | ||
| if (!timeRemaining || !display) return; | ||
| //what ever we input is turned into seconds | ||
| let totalSeconds = parseInt(timeRemaining.value); | ||
|
|
||
| if (isNaN(totalSeconds) || totalSeconds <= 0) return; | ||
|
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. Nice input validation. How could you inform the users that the input was invalid?
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. Hi @Luro91, Thank you for your feedback. I have updated the element by putting in a placeholder with shadowed text. I have also thrown in an error message which let's the user know what they need to do. 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. Nice. Looks good |
||
|
|
||
| const formattedTime = (seconds) => { | ||
| const mins = Math.floor(seconds / 60) | ||
| .toString() | ||
| .padStart(2, "0"); | ||
| const secs = (seconds % 60).toString().padStart(2, "0"); | ||
| return `${mins}:${secs}`; | ||
| }; | ||
|
|
||
| display.innerHTML = `Time Remaining: ${formattedTime(totalSeconds)}`; | ||
|
|
||
| alarmInterval = setInterval(() => { | ||
| totalSeconds--; | ||
|
|
||
| display.innerHTML = `Time Remaining: ${formattedTime(totalSeconds)}`; | ||
|
|
||
| if (totalSeconds <= 0) { | ||
| clearInterval(alarmInterval); | ||
| playAlarm(); | ||
| } | ||
| }, 1000); | ||
| } | ||
| //add color changing background when alarm reaches 0 until stopped. | ||
| //function from color changing assignment 10 year ago! | ||
| function makeRandomColor() { | ||
| let colorOptions = "0123456789ABCDEF"; | ||
| let newColor = "#"; | ||
| //repeat 6 times to generate 6 random hex digits from the 16 characters in colorOptions | ||
| for (let i = 0; i < 6; i++) { | ||
| //picks random numbers from colorOptions and appends it to the # to make a new color. | ||
| newColor += colorOptions[Math.floor(Math.random() * 16)]; | ||
| } | ||
| return newColor; | ||
| } | ||
| //end color changing | ||
|
|
||
| //keep the existing code below and call the setup | ||
| //set the background color transition | ||
| document.body.style.transition = "background-color 0.7s ease"; | ||
| // call the entire page | ||
| window.addEventListener("load", function () { | ||
|
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. Nice that you did the extension task with changing colors
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. Hi @Luro91, Thank you for your feedback. |
||
| // attach the alarm sound to the make Random color so it starts changing when the alarm starts. | ||
| audio.addEventListener("play", () => { | ||
| // stops any previous color changing intervals | ||
| clearInterval(colorInterval); | ||
| //starts a new repeating timer and saves it's ID in colorInterval. setInterval runs every 2seconds | ||
| colorInterval = setInterval(() => { | ||
| //style the background and make it important! so it over-rides the style.css | ||
| document.body.style.setProperty( | ||
| "background-color", | ||
| makeRandomColor(), | ||
| "important" | ||
| ); | ||
| //closes setInterval after 1 seconds | ||
| }, 1000); | ||
| }); | ||
|
|
||
| audio.addEventListener("pause", () => { | ||
| clearInterval(colorInterval); | ||
| document.body.style.backgroundColor = ""; | ||
| }); | ||
| }); | ||
| //not sure that this is helping. The function works without it. | ||
| window.setAlarm = setAlarm; | ||
|
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 don't need to attach the function to the window object as the function is already declared in the file and available here in this file
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. Hi @Luro91, Thank you for your feedback. I have removed it. |
||
| //end linking | ||
|
|
||
| // DO NOT EDIT BELOW HERE | ||
|
|
||
|
|
||
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.
Nice that you clear the interval here so that the running countdown is stopped
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.
Hi @Luro91, Thank you for your feedback.