generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 201
Manchester| 25-ITP-Sep| Fithi Teklom| Sprint 3 | Alarm Clock #908
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
Fithi-Teklom
wants to merge
13
commits into
CodeYourFuture:main
Choose a base branch
from
Fithi-Teklom: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 5 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
8085c0c
added a tittle element
Fithi-Teklom b3ad0d8
updated the title
Fithi-Teklom d33934f
added a jest.config.js file
Fithi-Teklom 9c3ee51
passed all the tests
Fithi-Teklom bffd4b4
checked an empty value first and any error
Fithi-Teklom 7ded280
removed pauseAlarm from stop alarm function
Fithi-Teklom c9aa8f1
reset any flashing and playing audio
Fithi-Teklom 0b85c7a
added space
Fithi-Teklom e618de2
removed the set button variable
Fithi-Teklom 76f1971
alarm starts immediately
Fithi-Teklom b6af9d4
formatted it
Fithi-Teklom fc92b97
wrapped an implementation inside a function
Fithi-Teklom 0c30fdd
modifications are made when timer is set to 0
Fithi-Teklom 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,101 @@ | ||
| function setAlarm() {} | ||
|
|
||
|
|
||
| // function setAlarm() {} | ||
|
|
||
| let timeLeft = 0; | ||
| let timer = null; | ||
| let flashing = null; | ||
|
|
||
| // DOM references | ||
| window.addEventListener("DOMContentLoaded", () => { | ||
| // const display = document.getElementById("timeRemaining"); | ||
| const setButton = document.getElementById("set"); | ||
| const stopButton = document.getElementById("stop"); | ||
|
|
||
| // Event listeners | ||
| // if (setButton) setButton.addEventListener("click", () => playAlarm()); | ||
| if (stopButton) stopButton.addEventListener("click", stopAlarm); | ||
cjyuan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // Show 00:00 on load | ||
| updateDisplay(0); | ||
| }); | ||
|
|
||
| // ------------------------------- | ||
| // FUNCTIONS | ||
| // ------------------------------- | ||
|
|
||
| function setAlarm() { | ||
| const inputEl = document.getElementById("alarmSet"); | ||
| const input = inputEl.value.trim(); | ||
|
|
||
| // Check empty input | ||
| if (input === "") { | ||
| alert("Please enter a number of seconds."); | ||
| return; | ||
| } | ||
|
|
||
| const parsed = parseInt(input, 10); | ||
|
|
||
| // Check invalid or negative number | ||
| if (isNaN(parsed) || parsed < 0) { | ||
| alert("Please enter a valid non-negative number."); | ||
| return; | ||
| } | ||
|
|
||
| timeLeft = parsed; | ||
|
|
||
| // Update display immediately | ||
| updateDisplay(timeLeft); | ||
|
|
||
| // Clear previous countdown | ||
| clearInterval(timer); | ||
|
|
||
cjyuan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // Start countdown every 1000ms | ||
| timer = setInterval(() => { | ||
| if (timeLeft > 0) { | ||
| timeLeft--; | ||
| updateDisplay(timeLeft); | ||
| } | ||
|
|
||
| if (timeLeft === 0) { | ||
| clearInterval(timer); | ||
| startAlarm(); | ||
| } | ||
| }, 1000); | ||
| } | ||
|
||
|
|
||
| function updateDisplay(seconds) { | ||
| const mins = String(Math.floor(seconds / 60)).padStart(2, "0"); | ||
| const secs = String(seconds % 60).padStart(2, "0"); | ||
|
|
||
| const display = document.getElementById("timeRemaining"); | ||
| if (!display) return; | ||
| display.textContent = `Time Remaining: ${mins}:${secs}`; | ||
| } | ||
|
|
||
| function startAlarm() { | ||
| playAlarm(); | ||
|
|
||
| // Flashing background | ||
| if (!flashing){ | ||
| flashing = setTimeout(() => { | ||
| document.body.style.backgroundColor = | ||
| document.body.style.backgroundColor === "red" ? "orange" : "red"; | ||
| }, 300); | ||
| } | ||
| } | ||
|
|
||
| function stopAlarm() { | ||
| if (typeof pauseAlarm === "function") pauseAlarm(); | ||
|
|
||
| clearInterval(flashing); | ||
| flashing = null; | ||
| document.body.style.backgroundColor = ""; | ||
| } | ||
|
|
||
|
|
||
| // module.exports= setAlarm; | ||
|
|
||
|
|
||
| // 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| /** @type {import('jest').Config} */ | ||
| module.exports = { | ||
| testEnvironment: "jsdom", | ||
| verbose: true, | ||
| testMatch: ["**/*.test.js"], | ||
| }; |
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
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.
Uh oh!
There was an error while loading. Please reload this page.