-
-
Notifications
You must be signed in to change notification settings - Fork 281
Birmingham | ITP-Jan | Roman Sanaye | Sprint 3 | Alarm-clock #1080
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
RomanSanaye
wants to merge
4
commits into
CodeYourFuture:main
Choose a base branch
from
RomanSanaye: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
4 commits
Select commit
Hold shift + click to select a range
15c47ae
alarmclock implemented and tests pass
RomanSanaye 5935fcb
Add dedicated resetAlarm function to ensure clean initial state
RomanSanaye c4446ac
inner function place at the beginning of the parent function
RomanSanaye a6783da
Refactor alarm app: improve scope, remove redundancy, and fix timer l…
RomanSanaye 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,17 +1,94 @@ | ||
| function setAlarm() {} | ||
| // DOM elements | ||
| const setAlarmBtn = document.getElementById("set"); | ||
| const stopAlarmBtn = document.getElementById("stop"); | ||
| const timeRemaining = document.getElementById("timeRemaining"); | ||
| let alarmInterval; | ||
|
|
||
| // Update Display function; | ||
| function updateDisplay(secondsValue) { | ||
| let minutes = Math.floor(secondsValue / 60); | ||
| let seconds = secondsValue % 60; | ||
| timeRemaining.innerText = `Time Remaining: ${String(minutes).padStart(2, "0")}:${String(seconds).padStart(2, "0")}`; | ||
| } | ||
|
|
||
| // reset function - returns app to clean initial state | ||
| function resetAlarm() { | ||
| function resetToInitialState() { | ||
| updateDisplay(0); | ||
| document.getElementById("alarmSet").value = ""; | ||
| stopAlarmBtn.style.display = "none"; | ||
| setAlarmBtn.style.display = "inline-block"; // ADD THIS - show set button | ||
| } | ||
|
|
||
| function stopSound() { | ||
| if (typeof pauseAlarm === "function") { | ||
| pauseAlarm(); | ||
| } | ||
| } | ||
|
cjyuan marked this conversation as resolved.
|
||
| // Clear any running interval | ||
| if (alarmInterval) { | ||
| clearInterval(alarmInterval); | ||
| alarmInterval = null; | ||
| } | ||
|
|
||
| resetToInitialState(); | ||
| stopSound(); | ||
| } | ||
|
|
||
| // Set Alarm function | ||
| function setAlarm() { | ||
| let totalSeconds; | ||
| const input = document.getElementById("alarmSet"); | ||
| const timeValue = parseInt(input.value); | ||
| const hasActiveTimer = alarmInterval !== null; | ||
|
|
||
| function startTimer() { | ||
| alarmInterval = setInterval(() => { | ||
| totalSeconds--; | ||
| updateDisplay(totalSeconds); | ||
| if (totalSeconds === 0) { | ||
| clearInterval(alarmInterval); | ||
| alarmInterval = null; | ||
|
|
||
| // WHEN ALARM STARTS: hide set button, show only stop button | ||
| setAlarmBtn.style.display = "none"; | ||
| stopAlarmBtn.style.display = "inline-block"; | ||
|
|
||
| playAlarm(); | ||
| } | ||
| }, 1000); | ||
| } | ||
|
|
||
| resetAlarm(); | ||
|
|
||
| if (isNaN(timeValue) || timeValue <= 0) { | ||
| if (!hasActiveTimer) alert("Please enter a number greater than 0"); | ||
| return; | ||
| } | ||
|
|
||
| totalSeconds = timeValue; | ||
| stopAlarmBtn.style.display = "inline-block"; | ||
| setAlarmBtn.style.display = "inline-block"; // Ensure set button is visible | ||
| updateDisplay(totalSeconds); | ||
| startTimer(); | ||
| } | ||
|
|
||
| document.getElementById("stop").addEventListener("click", () => { | ||
| pauseAlarm(); | ||
| resetAlarm(); | ||
| }); | ||
|
|
||
| // DO NOT EDIT BELOW HERE | ||
|
|
||
| var audio = new Audio("alarmsound.mp3"); | ||
|
|
||
| function setup() { | ||
| // Ensure clean initial state when page loads | ||
| resetAlarm(); | ||
|
|
||
| document.getElementById("set").addEventListener("click", () => { | ||
| setAlarm(); | ||
| }); | ||
|
|
||
| document.getElementById("stop").addEventListener("click", () => { | ||
| pauseAlarm(); | ||
| }); | ||
|
Comment on lines
-11
to
-14
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 don't have to delete this. You can just perform |
||
| } | ||
|
|
||
| function playAlarm() { | ||
|
|
||
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 |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| // jest.setup.js | ||
| require("@testing-library/jest-dom/extend-expect"); |
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.
Could also consider
visibility: hidden(suggestion: look up the difference betweendisplay: noneandvisibility: falsedisabledproperty(No change required)