-
-
Notifications
You must be signed in to change notification settings - Fork 283
West Midlands | 25-ITP-Sep | Baba Yusuf | Sprint 3 | Alarm Clock #900
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
Closed
Closed
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
11e30f5
Add initial implementation of mean calculation and tests
Baba05206 3cb29a0
Refactor mean calculation and tests for clarity and functionality
Baba05206 3d4c407
Update mean.js
Baba05206 b235bd1
Implement alarm functionality and update title in HTML
Baba05206 a4fcc54
Remove unnecessary blank line in setAlarm function
Baba05206 5aa6e97
deleted prep
80cc2eb
Merge branch 'CodeYourFuture:main' into alarm-clock
Baba05206 50a0653
Updated code to reflected all 6 improvements recommended
Baba05206 9a76928
Refactor - Added formatTimeDisplay utility function to reduce code du…
Baba05206 6948ee0
refactored code as per the 3 comments to improve accessibility, preve…
Baba05206 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,55 @@ | ||
| function setAlarm() {} | ||
| // Constants for time conversion | ||
| const SECONDS_PER_MINUTE = 60; | ||
| const MILLISECONDS_PER_SECOND = 1000; | ||
|
|
||
| let intervalId; | ||
|
|
||
| /** | ||
| * Formats time in seconds to MM:SS format | ||
| * @param {number} totalSeconds - The time in seconds to format | ||
| * @returns {string} Formatted time string in "Time Remaining: MM:SS" format | ||
| */ | ||
| function formatTimeDisplay(totalSeconds) { | ||
| const minutes = Math.floor(totalSeconds / SECONDS_PER_MINUTE); | ||
| const seconds = totalSeconds % SECONDS_PER_MINUTE; | ||
|
|
||
| return ( | ||
| "Time Remaining: " + | ||
| String(minutes).padStart(2, "0") + | ||
| ":" + | ||
| String(seconds).padStart(2, "0") | ||
| ); | ||
| } | ||
|
|
||
| function setAlarm() { | ||
| const input = document.getElementById("alarmSet"); | ||
| const heading = document.getElementById("timeRemaining"); | ||
|
|
||
| let totalSeconds = Number(input.value); | ||
|
|
||
| // Input validation: check for invalid or non-positive numbers | ||
| if (isNaN(totalSeconds) || totalSeconds <= 0) { | ||
| heading.innerText = "Please enter a valid positive number of seconds"; | ||
| return; | ||
| } | ||
|
|
||
| clearInterval(intervalId); | ||
|
cjyuan marked this conversation as resolved.
Comment on lines
+53
to
+54
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. Could consider placing all the "resetting" code together (code on lines 54 and 28). |
||
|
|
||
| heading.innerText = formatTimeDisplay(totalSeconds); | ||
|
|
||
| intervalId = setInterval(() => { | ||
| totalSeconds--; | ||
|
|
||
| if (totalSeconds <= 0) { | ||
| heading.innerText = formatTimeDisplay(0); | ||
| clearInterval(intervalId); | ||
| playAlarm(); | ||
| return; | ||
| } | ||
|
|
||
| heading.innerText = formatTimeDisplay(totalSeconds); | ||
| }, MILLISECONDS_PER_SECOND); | ||
| } | ||
|
|
||
| // DO NOT EDIT BELOW HERE | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Some input that can mess up the clock display can still pass this check.