-
-
Notifications
You must be signed in to change notification settings - Fork 281
London | 26-ITP-JAN | Shuheda Begum | Sprint 3 | Alarm Clock #1008
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 8 commits
419218d
b2d54f4
ee3dc7d
3c60cb0
90e99cf
c6fcdd6
1724a28
f363ec0
7ead5c3
f691b29
3f63303
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,59 @@ | ||
| function setAlarm() {} | ||
| let timerInterval = null; | ||
| let remainingSeconds = 0; | ||
|
|
||
| // Resets timer state | ||
| function resetTimer() { | ||
| if (timerInterval !== null) { | ||
| clearInterval(timerInterval); | ||
| timerInterval = null; | ||
| } | ||
| remainingSeconds = 0; | ||
| } | ||
|
cjyuan marked this conversation as resolved.
|
||
| //Starts the alarm counbtdown | ||
| function setAlarm() { | ||
| // Read the minutes value from the alarm input field | ||
| const minutesInput = document.getElementById("alarmSet"); | ||
| const seconds = parseInt(minutesInput.value, 10); | ||
| // Ignore invalid or non-positive input | ||
|
|
||
| if (isNaN(seconds) || seconds <= 0) { | ||
| return; | ||
| } | ||
|
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. Indentation is off. Have you installed the prettier VSCode extension and enabled "Format on save/paste" on VSCode, If you have enabled "Format on save" but it is not working, it is likely that you haven't assign a formatter for JS file. This could happen if you have zero or multiple extensions that can format .js file. If you have installed "Prettier" extension. To assign it as the formatter of JS code, you can try:
See: https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode
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. it seems it wasn't on. i've applied this now. |
||
| // Reset any existing timer first | ||
| resetTimer(); | ||
|
|
||
| // Store the input as the remaining seconds to count down | ||
| remainingSeconds = seconds; | ||
|
|
||
| // Update display immediately | ||
| updateTimeDisplay(); | ||
|
|
||
| // Start countdown | ||
| timerInterval = setInterval(() => { | ||
| remainingSeconds--; | ||
|
|
||
| updateTimeDisplay(); | ||
|
|
||
| if (remainingSeconds <= 0) { | ||
| resetTimer(); | ||
| updateTimeDisplay(); | ||
| playAlarm(); | ||
| } | ||
| }, 1000); | ||
| } | ||
|
|
||
| // Converts remainingSeconds into MM:SS format and updates the display | ||
| function updateTimeDisplay() { | ||
| const minutes = Math.floor(remainingSeconds / 60); | ||
|
cjyuan marked this conversation as resolved.
|
||
| const seconds = remainingSeconds % 60; | ||
|
|
||
| const formattedMinutes = minutes.toString().padStart(2, "0"); | ||
| const formattedSeconds = seconds.toString().padStart(2, "0"); | ||
|
|
||
| const timeDisplay = document.getElementById("timeRemaining"); | ||
| timeDisplay.textContent = `Time Remaining: ${formattedMinutes}:${formattedSeconds}`; | ||
| } | ||
|
|
||
|
|
||
| // DO NOT EDIT BELOW HERE | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.