-
-
Notifications
You must be signed in to change notification settings - Fork 327
London | 26-ITP-May | Rizqah Popoola | Sprint 3 | Alarm Clock #1357
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 5 commits
30f9803
0161e64
a296952
3a14a0e
33c4e01
383b8bf
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,5 +1,49 @@ | ||
| function setAlarm() {} | ||
| // ## How the clock should work | ||
|
|
||
| // When you click the `Set Alarm` button the counter at the top of the screen should change to the number you entered in the `input` field. For example, if the `input` field says `10` then the title should say `Time Remaining: 00:10`. | ||
|
|
||
| // Every one second the title should count down by one. | ||
|
|
||
| // When the `Time Remaining` reaches `00:00` the alarm should play a sound. You can make the sound happen by using `playAlarm()`. | ||
|
|
||
| // You can stop the alarm sound by pressing the `Stop Alarm` button. | ||
| const alarmInput = document.querySelector("#alarmSet"); | ||
| const timeRemaining = document.querySelector("#timeRemaining"); | ||
|
|
||
| let timer; | ||
| function setAlarm() { | ||
| clearInterval(timer); | ||
| pauseAlarm(); | ||
| let totalSeconds = Math.round(Number(alarmInput.value)); | ||
|
|
||
| if (totalSeconds > 36000) { | ||
| alert("Please enter a time less than 10 hours."); | ||
| updateTime(0); | ||
| return; | ||
| } | ||
| if (alarmInput.value === "" || totalSeconds < 0 || !Number.isInteger(0)) { | ||
| alert("Please enter a valid positive time."); | ||
| updateTime(0); | ||
| return; | ||
| } | ||
| alarmInput.value = ""; | ||
| updateTime(totalSeconds); | ||
|
|
||
| timer = setInterval(() => { | ||
| if (totalSeconds <= 0) { | ||
| clearInterval(timer); | ||
| playAlarm(); | ||
| } | ||
| updateTime(totalSeconds--); | ||
| }, 1000); | ||
|
Comment on lines
+39
to
47
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. With this change, there will always be a one second delay before the alarm sound.
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 think I Have fixed this now. THank you |
||
| } | ||
|
|
||
| function updateTime(secs) { | ||
| const minutes = String(Math.floor(secs / 60)).padStart(2, "0"); | ||
| const seconds = String(secs % 60).padStart(2, "0"); | ||
|
|
||
| timeRemaining.innerText = `Time Remaining: ${minutes}:${seconds}`; | ||
| } | ||
| // DO NOT EDIT BELOW HERE | ||
|
|
||
| var audio = new Audio("alarmsound.mp3"); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
falseeven iftotalSecondsisNaN.