-
-
Notifications
You must be signed in to change notification settings - Fork 279
London | 26-ITP-Jan | Xuanming Hu | Sprint 3 | Alarm Clock App #1115
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 2 commits
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,32 @@ | ||
| function setAlarm() {} | ||
| let countdownInterval; | ||
|
|
||
| function setAlarm() { | ||
| const inputElement = document.getElementById("alarmSet"); | ||
| const timeDisplay = document.getElementById("timeRemaining"); | ||
|
|
||
| let timeRemaining = parseInt(inputElement.value, 10) || 0; | ||
|
|
||
| clearInterval(countdownInterval); | ||
|
|
||
| function updateDisplay() { | ||
| const minutes = String(Math.floor(timeRemaining / 60)).padStart(2, "0"); | ||
| const seconds = String(timeRemaining % 60).padStart(2, "0"); | ||
| timeDisplay.innerText = `Time Remaining: ${minutes}:${seconds}`; | ||
| } | ||
|
|
||
| updateDisplay(); | ||
|
|
||
| countdownInterval = setInterval(() => { | ||
| timeRemaining--; | ||
|
|
||
| if (timeRemaining <= 0) { | ||
| clearInterval(countdownInterval); | ||
| playAlarm(); | ||
|
Comment on lines
+25
to
+26
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. What does the countdown show when the alarm plays?
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. Because |
||
| } else { | ||
| updateDisplay(); | ||
| } | ||
| }, 1000); | ||
| } | ||
|
|
||
| // DO NOT EDIT BELOW HERE | ||
|
|
||
|
|
||
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.
Nice that the old interval is cleared when the alarm is set again
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.
Thanks