-
-
Notifications
You must be signed in to change notification settings - Fork 281
London | 26-ITP-Jan | Miriam Jorna | Sprint 3 | Alarmclock #1192
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
base: main
Are you sure you want to change the base?
Changes from all commits
bc46214
724f78e
b5531bb
fa5b440
3fb860f
055596b
57ab5ca
3453a0c
459b265
0a1c10e
0df1cfb
16a4347
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,46 @@ | ||
| function setAlarm() {} | ||
| let countdownId; | ||
|
|
||
| // moved to outer scope, takes seconds as a parameter | ||
| function updateDisplay(seconds) { | ||
| const minutes = Math.floor(seconds / 60); | ||
| const remainingSeconds = seconds % 60; | ||
| document.getElementById("timeRemaining").textContent = | ||
| `Time Remaining: ${String(minutes).padStart(2, "0")}:${String(remainingSeconds).padStart(2, "0")}`; | ||
| } | ||
|
|
||
| // reset before starting new countdown | ||
| function resetAlarm() { | ||
| clearInterval(countdownId); | ||
| audio.pause(); | ||
| audio.currentTime = 0; | ||
| updateDisplay(0); | ||
| document.body.classList.toggle("alarm-activated", false); | ||
| } | ||
|
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. Shouldn't this function, You should also reset the audio because the user may not click the Stop button before starting a new countdown.
Author
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. Implemented. Thank you for your time! |
||
|
|
||
| function setAlarm() { | ||
| resetAlarm(); | ||
| let seconds = parseInt(document.getElementById("alarmSet").value); | ||
|
|
||
| if (!seconds || seconds < 1) { | ||
| alert("The number of seconds must be higher than 0 please"); | ||
| return; | ||
| } | ||
|
|
||
| updateDisplay(seconds); | ||
| // pass seconds as argument and update immediately on click | ||
|
|
||
| countdownId = setInterval(() => { | ||
| seconds--; | ||
| updateDisplay(seconds); | ||
| // pass seconds as argument | ||
|
|
||
| if (seconds <= 0) { | ||
| clearInterval(countdownId); | ||
| playAlarm(); | ||
| document.body.classList.toggle("alarm-activated", true); | ||
| } | ||
| }, 1000); | ||
| } | ||
|
|
||
| // DO NOT EDIT BELOW HERE | ||
|
cjyuan marked this conversation as resolved.
|
||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.