generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 193
West Midlands | ITP-Sept-25 | Georgina Rogers | Sprint 3 | Alarm Clock #905
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
zilinskyte
wants to merge
5
commits into
CodeYourFuture:main
Choose a base branch
from
zilinskyte:alarm-clock
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
5 commits
Select commit
Hold shift + click to select a range
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,19 +1,74 @@ | ||
| function setAlarm() {} | ||
| let timer = null; | ||
| let totalSeconds = 0; | ||
|
|
||
| // DO NOT EDIT BELOW HERE | ||
| function formatTime(seconds) { | ||
| const mins = Math.floor(seconds / 60); | ||
| const secs = seconds % 60; | ||
| return `${String(mins).padStart(2, "0")}:${String(secs).padStart(2, "0")}`; | ||
| } | ||
|
|
||
| var audio = new Audio("alarmsound.mp3"); | ||
| function parseInputTime(value) { | ||
| if (!/^\d{2}:\d{2}$/.test(value)) return null; | ||
| const [m, s] = value.split(":").map(Number); | ||
| if (s > 59) return null; | ||
| return m * 60 + s; | ||
| } | ||
|
|
||
| function updateDisplay() { | ||
| document.getElementById("alarmSet").value = formatTime(totalSeconds); | ||
| document.getElementById("timeRemaining").textContent = `Time Remaining: ${formatTime(totalSeconds)}`; | ||
| } | ||
|
|
||
| function incrementTime(amount) { | ||
| totalSeconds += amount; | ||
| if (totalSeconds < 0) totalSeconds = 0; | ||
| updateDisplay(); | ||
| } | ||
|
|
||
| function setAlarm() { | ||
| const input = document.getElementById("alarmSet"); | ||
| const parsed = parseInputTime(input.value); | ||
| if (parsed === null) { | ||
| alert("Use MM:SS format"); | ||
| return; | ||
| } | ||
|
|
||
| function setup() { | ||
| document.getElementById("set").addEventListener("click", () => { | ||
| setAlarm(); | ||
| }); | ||
| totalSeconds = parsed; | ||
| updateDisplay(); | ||
|
|
||
| document.getElementById("stop").addEventListener("click", () => { | ||
| pauseAlarm(); | ||
| }); | ||
| if (timer) clearInterval(timer); | ||
|
|
||
| timer = setInterval(() => { | ||
| totalSeconds--; | ||
| updateDisplay(); | ||
| if (totalSeconds <= 0) { | ||
| clearInterval(timer); | ||
| timer = null; | ||
| playAlarm(); | ||
| } | ||
| }, 1000); | ||
| } | ||
|
|
||
| function stopTimer() { | ||
| if (timer) { | ||
| clearInterval(timer); | ||
| timer = null; | ||
| } | ||
| totalSeconds = 0; | ||
| updateDisplay(); | ||
| pauseAlarm(); | ||
| } | ||
|
|
||
| // attach to window so HTML buttons can call them | ||
| window.incrementTime = incrementTime; | ||
| window.setAlarm = setAlarm; | ||
| window.stopTimer = stopTimer; | ||
|
Comment on lines
+63
to
+65
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. Are you aware of some of the pros and cons between these two approaches of invoking a callback function? |
||
| window.playAlarm = playAlarm; | ||
| window.pauseAlarm = pauseAlarm; | ||
|
|
||
| // DO NOT EDIT BELOW HERE | ||
| var audio = new Audio("alarmsound.mp3"); | ||
|
|
||
| function playAlarm() { | ||
| audio.play(); | ||
| } | ||
|
|
@@ -22,4 +77,5 @@ function pauseAlarm() { | |
| audio.pause(); | ||
| } | ||
|
|
||
| window.onload = setup; | ||
|
|
||
|
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,63 @@ | ||
| .centre { | ||
| position: fixed; | ||
| top: 50%; | ||
| left: 50%; | ||
| -webkit-transform: translate(-50%, -50%); | ||
| transform: translate(-50%, -50%); | ||
| .container { | ||
| font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif; | ||
| display: flex; | ||
| flex-direction: column; | ||
| align-items: center; | ||
| justify-content: center; | ||
| height: 100vh; | ||
| gap: 15px; | ||
| } | ||
|
|
||
| #alarmSet { | ||
| margin: 20px; | ||
| .time-label { | ||
| font-size: 44px; | ||
| font-weight: bold; | ||
| } | ||
|
|
||
| h1 { | ||
| .time-input { | ||
| font-size: 64px; | ||
| text-align: center; | ||
| width: 200px; | ||
| padding: 15px; | ||
| border-radius: 10px; | ||
| border: 3px solid #0904b0; | ||
| } | ||
|
|
||
| .increment-buttons { | ||
| display: flex; | ||
| gap: 10px; | ||
| } | ||
|
|
||
| .increment-buttons button { | ||
| font-size: 20px; | ||
| padding: 10px 15px; | ||
| border-radius: 6px; | ||
| border: 2px solid #444; | ||
| } | ||
|
|
||
| .set-button { | ||
| font-size: 30px; | ||
| padding: 10px 20px; | ||
| border-radius: 8px; | ||
| border: 3px solid green; | ||
| } | ||
|
|
||
| .time-remaining { | ||
| font-size: 36px; | ||
| font-weight: 900; | ||
| text-align: center; | ||
| } | ||
|
|
||
| .stop-button { | ||
| font-size: 40px; | ||
| padding: 15px 30px; | ||
| border-radius: 10px; | ||
| border: 4px solid red; | ||
| } | ||
|
|
||
| .stop-large-button { | ||
| font-size: 40px; | ||
| padding: 15px 30px; | ||
| border-radius: 10px; | ||
| border: 4px solid red; | ||
| } | ||
|
|
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.
Can you think of anything else that should also be reset before starting a new countdown?