Repository navigation
Cape Town | 26-ITP-Sept | Leigh Ross | Sprint 3 | Build an alarm clock app #1511
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
leigh-ross
wants to merge
6
commits into
CodeYourFuture:main
Choose a base branch
from
leigh-ross:coursework/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
6 commits
Select commit
Hold shift + click to select a range
8631a7e
Changed title to Alarm clock app
leigh-ross f8bede4
added placeholder styling for the buttons: set alarm and stop alarm
leigh-ross 429a01e
implemented a function to convert seconds to mm:ss
leigh-ross bfa790f
Implemented setAlarm function to set the alarm and interval for the c…
leigh-ross e21d19b
added funny hamster image change when alarm is set and stopped. box f…
leigh-ross e02dac6
Restricted flashing to 20 times but alarm sound still plays
leigh-ross 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,56 @@ | ||
| function setAlarm() {} | ||
| let countdownTimer; | ||
| let flashTimer; | ||
| let currentSeconds; | ||
|
|
||
| function setAlarm() { | ||
| clearInterval(countdownTimer); | ||
| // fetch seconds input | ||
| currentSeconds = Number(document.getElementById("alarmSet").value); | ||
| document.body.style.backgroundImage = "url('alarmsethamster.jfif')"; | ||
| document.body.style.backgroundPosition = "centre"; | ||
| // set time remaining to seconds input | ||
| document.getElementById("timeRemaining").textContent = | ||
| `Time Remaining: ${formatTime(currentSeconds)}`; | ||
|
|
||
| // handling the interval and alarm end | ||
| countdownTimer = setInterval(() => { | ||
| currentSeconds = currentSeconds - 1; | ||
|
|
||
| document.getElementById("timeRemaining").textContent = | ||
| `Time Remaining: ${formatTime(currentSeconds)}`; | ||
|
|
||
| if (currentSeconds <= 0) { | ||
| clearInterval(countdownTimer); | ||
| playAlarm(); | ||
| document.getElementById("timeRemaining").textContent = | ||
| `Time Remaining: 00:00`; | ||
|
|
||
| // img change | ||
| document.body.style.backgroundImage = "url('alarmplaysoundhamster.jfif')"; | ||
| document.body.style.backgroundPosition = "center"; | ||
|
|
||
| // box turns red | ||
| let flashCount = 0; | ||
| const box = document.querySelector(".centre"); | ||
| flashTimer = setInterval(() => { | ||
| box.classList.toggle("red-bg"); | ||
| flashCount++ | ||
| if (flashCount >= 20){ | ||
| clearInterval(flashTimer); | ||
| } | ||
| }, 500); | ||
| } | ||
| }, 1000); | ||
| } | ||
|
|
||
| function formatTime(totalSeconds) { | ||
| // converts the seconds to minutes and seconds and returns "mm:ss" | ||
| const convertToMinutes = Math.floor(totalSeconds / 60); | ||
| const remainderSeconds = totalSeconds % 60; | ||
| const paddedMinutes = String(convertToMinutes).padStart(2, "0"); | ||
| const paddedSeconds = String(remainderSeconds).padStart(2, "0"); | ||
| return `${paddedMinutes}:${paddedSeconds}`; | ||
| } | ||
|
|
||
| // DO NOT EDIT BELOW HERE | ||
|
|
||
|
|
@@ -23,3 +75,10 @@ function pauseAlarm() { | |
| } | ||
|
|
||
| window.onload = setup; | ||
|
|
||
| document.getElementById("stop").addEventListener("click", () => { | ||
| document.body.style.backgroundImage = "url('alarmsethamster.jfif')"; | ||
| document.body.style.backgroundPosition = "center"; | ||
| clearInterval(countdownTimer); | ||
| clearInterval(flashTimer); | ||
|
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. After Stop clears To "like" or "dislike" this comment, please follow this link |
||
| }); | ||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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.
If Set Alarm is clicked while the previous alarm is still flashing, what happens to the existing
flashTimer?To "like" or "dislike" this comment, please follow this link