-
-
Notifications
You must be signed in to change notification settings - Fork 320
London | 26-ITP-May | Dipa Sarker | Sprint 3 | Alarm Clock App #1294
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
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 |
|---|---|---|
|
|
@@ -23,3 +23,59 @@ function pauseAlarm() { | |
| } | ||
|
|
||
| window.onload = setup; | ||
|
|
||
| const timeRemainingElement = document.querySelector("#timeRemaining"); | ||
| const alarmSetElement = document.querySelector("#alarmSet"); | ||
| const setButtonElement = document.querySelector("#set"); | ||
| const stopButtonElement = document.querySelector("#stop"); | ||
| const bodyElement = document.querySelector("body"); | ||
| const alarmSoundElement = document.querySelector("#alarmSound"); | ||
|
|
||
| let remainingTime; | ||
| let intervalID; | ||
| function triggerAlarm() { | ||
|
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. A bit more spacing between functions / improved formatting would help readability.
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. Actually, I used prettier tool according to the style guide for formatting. Should I provide extra spaces in between functions? |
||
| bodyElement.style.backgroundColor = "yellow"; | ||
| alarmSoundElement.play(); | ||
| } | ||
| function setAlarm() { | ||
|
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. Have you properly handled the input validation here?
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. No, I didn't handle input validation. Now I have tried with empty input and input time < 0. |
||
| clearInterval(intervalID); | ||
| const alarmTime = alarmSetElement.value; | ||
| if (alarmTime === "") { | ||
| return; | ||
| } | ||
| remainingTime = Number(alarmTime); | ||
| if (remainingTime < 0) { | ||
| return; | ||
| } | ||
| const showTimeMinutes = Math.floor(remainingTime / 60) | ||
| .toString() | ||
| .padStart(2, "0"); | ||
| const showTimeSeconds = (remainingTime % 60).toString().padStart(2, "0"); | ||
| timeRemainingElement.innerText = showTimeMinutes + ":" + showTimeSeconds; | ||
| if (remainingTime === 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. Do you properly finish the timer countdown after it hits zero?
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. Sorry, I am unclear about your question. But I think I finished the countdown after hitting zero at here: function countDown() { Which means:
|
||
| triggerAlarm(); | ||
| } else { | ||
| intervalID = setInterval(countDown, 1000); | ||
| } | ||
| } | ||
| setButtonElement.addEventListener("click", setAlarm); | ||
| function countDown() { | ||
| if (remainingTime <= 0) { | ||
| clearInterval(intervalID); | ||
| triggerAlarm(); | ||
| return; | ||
| } | ||
| remainingTime -= 1; | ||
| const remainingMinutes = Math.floor(remainingTime / 60) | ||
| .toString() | ||
| .padStart(2, "0"); | ||
| const remainingSeconds = (remainingTime % 60).toString().padStart(2, "0"); | ||
| timeRemainingElement.innerText = remainingMinutes + ":" + remainingSeconds; | ||
| } | ||
| function stopAlarm() { | ||
| clearInterval(intervalID); | ||
| alarmSoundElement.pause(); | ||
| alarmSoundElement.currentTime = 0; | ||
| bodyElement.style.backgroundColor = ""; | ||
| } | ||
| stopButtonElement.addEventListener("click", stopAlarm); | ||
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.
If you know you are using IDs, can you think of something better tha n querySelector?
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.
Is it getelementID()?