-
-
Notifications
You must be signed in to change notification settings - Fork 254
London | JAN-ITP-26 | Kayanat Suleman | Sprint 3 | Alarm Clock App #969
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
ddb79fc
61fe419
7cafbef
6b24f06
eb90347
5d17875
2177f21
75dc638
8a454bf
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,52 @@ | ||
| function setAlarm() {} | ||
| let intervalId = null; | ||
|
|
||
| function formatTime(totalSeconds) { | ||
| const minutes = Math.floor(totalSeconds / 60); | ||
| const seconds = totalSeconds % 60; | ||
|
|
||
| const formattedMinutes = String(minutes).padStart(2, "0"); | ||
| const formattedSeconds = String(seconds).padStart(2, "0"); | ||
|
|
||
| return `${formattedMinutes}:${formattedSeconds}`; | ||
| } | ||
|
|
||
| function setAlarm() { | ||
| const input = document.getElementById("alarmSet"); | ||
| const heading = document.getElementById("timeRemaining"); | ||
|
|
||
| let value = input.value | ||
|
|
||
| if (value === "") { | ||
| heading.innerText = "Please enter a number of seconds."; | ||
| return; | ||
| } | ||
|
|
||
| let remainingSeconds = Number(value); | ||
|
|
||
| if (remainingSeconds <= 0 || isNaN(remainingSeconds)) { | ||
| heading.innerText = "Please enter a positive number greater than 0."; | ||
| return; | ||
|
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. Also instead of
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. Thank you for the review comment. I have now updated the logic so that if the value is invalid (NaN) or less than or equal to zero, the app displays the message ("Please enter a positive number greater than 0.") rather than returning silently. |
||
| } | ||
|
|
||
| heading.innerText = `Time Remaining: ${formatTime(remainingSeconds)}`; | ||
|
|
||
| if (intervalId !== null) { | ||
| clearInterval(intervalId); | ||
| } | ||
|
|
||
| intervalId = setInterval(() => { | ||
| remainingSeconds -= 1; | ||
|
|
||
| if (remainingSeconds <= 0) { | ||
| heading.innerText = `Time Remaining: ${formatTime(0)}`; | ||
| playAlarm(); | ||
| clearInterval(intervalId); | ||
| intervalId = null; | ||
| return; | ||
| } | ||
| heading.innerText = `Time Remaining: ${formatTime(remainingSeconds)}`; | ||
| }, 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.
Instead of
returningit will be better to show the user an appropriate message, can you think of a way to do that please.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.
Hi @A-O-Emmanuel, thank you for the review comments. I have updated the validation so that if the input field is empty, the app now displays a user message ("Please enter a number of seconds.") instead of returning silently. This prevents the timer from starting without valid input.