-
-
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
Open
AngelaMcLeary
wants to merge
11
commits into
CodeYourFuture:main
Choose a base branch
from
AngelaMcLeary:Sprint-3/alarm-clock-app
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
ae8ac1f
update html title
AngelaMcLeary 8cd966d
Implement alarmclock.js
AngelaMcLeary 473b4a4
update css
AngelaMcLeary b2436d3
Merge branch 'main' into Sprint-3/alarm-clock-app
AngelaMcLeary 9ddf206
add color changing background and update card style
AngelaMcLeary dbc914a
format code
AngelaMcLeary 0146e8d
Merge remote-tracking branch 'refs/remotes/origin/Sprint-3/alarm-cloc…
AngelaMcLeary 3ef2c65
update time for color changing
AngelaMcLeary 6fcbfc7
changed variable declaration
AngelaMcLeary 843f431
add placeholder to hint to user about input data
AngelaMcLeary 3894cc5
update placeholder, update remove window onlad, update error message
AngelaMcLeary File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,87 @@ | ||
| function setAlarm() {} | ||
| let alarmInterval; | ||
| let colorInterval; | ||
| let errorTimeout; | ||
|
|
||
| function setAlarm() { | ||
| clearInterval(alarmInterval); | ||
| const timeRemaining = document.querySelector("#alarmSet"); | ||
| const display = document.querySelector("#timeRemaining"); | ||
| const error = document.querySelector("#error"); | ||
| if (!timeRemaining || !display || !error) return; | ||
| //what ever we input is turned into seconds | ||
| let totalSeconds = parseInt(timeRemaining.value); | ||
| // throw an error message if the user enters nothing and presses the alarm button. | ||
| if (isNaN(totalSeconds) || totalSeconds <= 0) { | ||
| error.textContent = "Please enter a valid number in seconds!"; | ||
| //set error to disappear after 3 seconds | ||
| clearTimeout(errorTimeout); | ||
| errorTimeout = setTimeout(() => { | ||
| error.textContent = ""; | ||
| }, 3000); | ||
| return; | ||
| } | ||
| 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 = ""; | ||
| }); | ||
| }); | ||
| //end linking | ||
|
|
||
| // DO NOT EDIT BELOW HERE | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.