-
-
Notifications
You must be signed in to change notification settings - Fork 281
Sheffield | 26-ITP-Jan | Mona-Eltantawy | Sprint 3| Alarm clock #1158
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
d598894
3eaa8c0
a204333
384a4dd
7210f43
83beeba
0e2fdf2
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,17 +1,48 @@ | ||
| function setAlarm() {} | ||
| var audio = new Audio("alarmsound.mp3"); | ||
|
|
||
| // DO NOT EDIT BELOW HERE | ||
|
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. I think your code should be above this line
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. I changed the whole page multiple times so I don't have the line now |
||
| let timeRemaining = 0; | ||
| let countdownInterval = null; | ||
|
|
||
| var audio = new Audio("alarmsound.mp3"); | ||
| function setAlarm() { | ||
| const input = document.getElementById("alarmSet").value; | ||
|
|
||
| function setup() { | ||
| document.getElementById("set").addEventListener("click", () => { | ||
| setAlarm(); | ||
| }); | ||
| timeRemaining = parseInt(input, 10); | ||
|
|
||
| if (isNaN(timeRemaining) || timeRemaining <= 0) { | ||
| console.error("Please enter a valid number greater than 0"); | ||
| return; | ||
| } | ||
|
|
||
| updateDisplay(); | ||
|
|
||
| if (countdownInterval) { | ||
| clearInterval(countdownInterval); | ||
| } | ||
|
|
||
| countdownInterval = setInterval(() => { | ||
| timeRemaining--; | ||
|
|
||
| updateDisplay(); | ||
|
|
||
| document.getElementById("stop").addEventListener("click", () => { | ||
| pauseAlarm(); | ||
| }); | ||
| if (timeRemaining <= 0) { | ||
| clearInterval(countdownInterval); | ||
| playAlarm(); | ||
| } | ||
| }, 1000); | ||
| } | ||
|
|
||
| function updateDisplay() { | ||
| const display = document.getElementById("timeRemaining"); | ||
|
|
||
| const minutes = String(Math.floor(timeRemaining / 60)).padStart(2, "0"); | ||
| const seconds = String(timeRemaining % 60).padStart(2, "0"); | ||
|
|
||
| display.textContent = `Time Remaining: ${minutes}:${seconds}`; | ||
| } | ||
|
|
||
| function setup() { | ||
| document.getElementById("set").addEventListener("click", setAlarm); | ||
| document.getElementById("stop").addEventListener("click", pauseAlarm); | ||
| } | ||
|
|
||
| function playAlarm() { | ||
|
|
@@ -20,6 +51,11 @@ function playAlarm() { | |
|
|
||
| function pauseAlarm() { | ||
| audio.pause(); | ||
| audio.currentTime = 0; | ||
|
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. Nice that you reset the audio time here |
||
|
|
||
| if (countdownInterval) { | ||
| clearInterval(countdownInterval); | ||
| } | ||
| } | ||
|
|
||
| window.onload = setup; | ||
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.
The html title should say "Alarm clock app"
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.
done
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.
I meant the title that is responsible for what is shown in the tab in the browser header. How can you change this?