generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 158
London | 25-ITP-May | Surafel Workneh | Sprint-3 | Alarmclock #687
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
Closed
Closed
Changes from all commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
7dcef8d
update JSon file
SuWebOnes a44d23e
update: installing required jsdom
SuWebOnes b864e83
up date json file
SuWebOnes 0cc242a
update: title for alarm in index.html
SuWebOnes 2612cde
update: update title in Alarm clock app in alarm/index.html
SuWebOnes 1699cc6
update: code for setting countdown and play audio
SuWebOnes ac94058
update: json files
SuWebOnes a356165
update: merge json file
SuWebOnes 370be42
update: fix json package
SuWebOnes 80e3a09
update: fix json
SuWebOnes 2445dcb
update: fix the path at the and put at very top of the line
SuWebOnes b481be3
update: fix code on Stops alarm sound if it’s still playing, Input va…
SuWebOnes b925ada
Initial commit: Add package-lock.json for module data groups
SuWebOnes d2d6856
Refactor: Rename title in reading-list and slideshow index.html files
SuWebOnes 3ffb6fa
feat: Implement basic slideshow functionality
SuWebOnes 58b21bc
feat: Add meta information to slideshow's package.json
SuWebOnes ef063cb
feat: Implement todo list functionality with deadlines and UI
SuWebOnes a04a2b6
style: Basic styling for todo list application
SuWebOnes bca41f2
update: reteach
SuWebOnes 5296d92
update: fix codes to do lists and remove in todo-list/script.js
SuWebOnes 229bf44
update: fix markups including comments for easy to fix in todo-list/html
SuWebOnes 605d475
update: markup with extra like Datepicker input in todo-list/index.html
SuWebOnes 79dac20
update: js code for advanced features including bulk deletion of comp…
SuWebOnes 671b9f8
update: fix package of json
SuWebOnes 531f862
update: reteach
SuWebOnes bcf3df9
update: fixing json packages
SuWebOnes 0c5c298
Merge branch 'main' into alarmclock
SuWebOnes 86d7e53
update: fix codes to do lists and remove in todo-list/script.js
SuWebOnes 07516dd
update: js code for advanced features including bulk deletion of comp…
SuWebOnes acd71f3
update JSon file
SuWebOnes 166b442
update: fixing json packages
SuWebOnes a3819e6
delete duplicated json package
SuWebOnes 0bb8a97
revert package json
SuWebOnes a4a8e00
update: alarm flash in alarmclock.js
SuWebOnes 1eb93b4
update: add pause resume in index.html
SuWebOnes ce05dda
t
SuWebOnes a945107
yu
SuWebOnes 8cf5e58
rv js alr
SuWebOnes 209e567
slideshowreverse_rmved_from alarm project
SuWebOnes a693a1c
revert and resolve conflict
SuWebOnes c81a944
rem col
SuWebOnes 3aa4e2a
resting jspak
SuWebOnes 8ecb32f
syntax
SuWebOnes 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,25 +1,132 @@ | ||
function setAlarm() {} | ||
let timeRemaining = 0; | ||
let intervalId; | ||
const audio = new Audio("alarmsound.mp3"); | ||
|
||
// DO NOT EDIT BELOW HERE | ||
/** | ||
* Sets the alarm countdown. | ||
* Validates input, resets alarm and timer. | ||
*/ | ||
function setAlarm() { | ||
const input = document.getElementById("alarmSet"); | ||
timeRemaining = parseInt(input.value, 10); | ||
|
||
var audio = new Audio("alarmsound.mp3"); | ||
// Validation: check for valid number | ||
if (isNaN(timeRemaining) || timeRemaining <= 0) { | ||
alert("Please enter a positive number of seconds."); | ||
return; | ||
} | ||
|
||
function setup() { | ||
document.getElementById("set").addEventListener("click", () => { | ||
setAlarm(); | ||
}); | ||
// Clear any existing countdown | ||
if (intervalId) { | ||
clearInterval(intervalId); | ||
SuWebOnes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
// Pause any currently playing alarm sound | ||
pauseAlarm(true); | ||
|
||
// Update the initial time display | ||
updateTimeDisplay(); | ||
|
||
// Start new interval countdown | ||
intervalId = setInterval(() => { | ||
timeRemaining--; | ||
updateTimeDisplay(); | ||
|
||
document.getElementById("stop").addEventListener("click", () => { | ||
pauseAlarm(); | ||
}); | ||
if (timeRemaining <= 0) { | ||
clearInterval(intervalId); | ||
playAlarm(); | ||
startFlashingBackground(); // Flash background when alarm finishes | ||
} | ||
}, 1000); | ||
} | ||
|
||
/** | ||
* Updates the countdown time on screen | ||
*/ | ||
function updateTimeDisplay() { | ||
const heading = document.getElementById("timeRemaining"); | ||
const minutes = Math.floor(timeRemaining / 60).toString().padStart(2, "0"); | ||
const seconds = (timeRemaining % 60).toString().padStart(2, "0"); | ||
heading.innerText = `Time Remaining: ${minutes}:${seconds}`; | ||
} | ||
|
||
/** | ||
* Plays the alarm sound from beginning | ||
*/ | ||
function playAlarm() { | ||
audio.currentTime = 0; | ||
audio.play(); | ||
} | ||
|
||
function pauseAlarm() { | ||
/** | ||
* Stops the alarm sound | ||
* @param {boolean} resetAudio - if true, reset to start | ||
*/ | ||
function pauseAlarm(resetAudio = false) { | ||
audio.pause(); | ||
if (resetAudio) { | ||
audio.currentTime = 0; | ||
} | ||
} | ||
|
||
/** | ||
* Flashes the background color when alarm finishes | ||
*/ | ||
function startFlashingBackground() { | ||
let flashCount = 0; | ||
const maxFlashes = 10; // Number of flashes (5 times) | ||
const originalColor = document.body.style.backgroundColor; | ||
const flashInterval = setInterval(() => { | ||
document.body.style.backgroundColor = | ||
document.body.style.backgroundColor === "red" ? "white" : "red"; | ||
flashCount++; | ||
if (flashCount >= maxFlashes) { | ||
clearInterval(flashInterval); | ||
document.body.style.backgroundColor = originalColor; | ||
} | ||
}, 300); | ||
} | ||
|
||
/** | ||
* Pauses the countdown timer | ||
*/ | ||
function pauseTimer() { | ||
if (intervalId) { | ||
clearInterval(intervalId); | ||
intervalId = null; | ||
} | ||
} | ||
|
||
/** | ||
* Resumes the countdown timer | ||
*/ | ||
function resumeTimer() { | ||
if (!intervalId && timeRemaining > 0) { | ||
intervalId = setInterval(() => { | ||
timeRemaining--; | ||
updateTimeDisplay(); | ||
|
||
if (timeRemaining <= 0) { | ||
clearInterval(intervalId); | ||
playAlarm(); | ||
startFlashingBackground(); | ||
} | ||
}, 1000); | ||
} | ||
} | ||
|
||
/** | ||
* Setup event listeners after page load | ||
*/ | ||
function setup() { | ||
// Set alarm button | ||
document.getElementById("set").addEventListener("click", setAlarm); | ||
// Stop alarm button | ||
document.getElementById("stop").addEventListener("click", () => pauseAlarm(true)); | ||
// Pause timer button | ||
document.getElementById("pause").addEventListener("click", pauseTimer); | ||
// Resume timer button | ||
document.getElementById("resume").addEventListener("click", resumeTimer); | ||
} | ||
|
||
window.onload = setup; | ||
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.