-
-
Notifications
You must be signed in to change notification settings - Fork 279
West Midlands | 25-ITP-Sept | Mustaf Asani | Sprint 3 | Feature/alarmclock #921
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 1 commit
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
5007c4b
added all tests to test, started mean.js but not finished
asaniDev f21c96e
predicted the result of each file before fixing them
asaniDev b058970
installed dependencies
asaniDev b63c6de
made up tests and then created functions to pass the required tests i…
asaniDev e17bf30
fixed invert function,answered questions and added tests to check it …
asaniDev 8196fd6
made alarm clock countdown from user input number and alarm sound whe…
asaniDev 29cacc9
made sure when input time is 0, alarm still works and added backgroun…
asaniDev 250453e
Revert "added all tests to test, started mean.js but not finished"
asaniDev 9819f2c
Revert "predicted the result of each file before fixing them"
asaniDev 6c486d4
Revert "installed dependencies"
asaniDev 3e235c6
Revert "made up tests and then created functions to pass the required…
asaniDev 9725399
Revert "fixed invert function,answered questions and added tests to c…
asaniDev da00a5e
removed unnecesary functions and reset timer
asaniDev 2454086
removed redundant code, added code to stop alarm if runnng
asaniDev b03f445
reordered the statements to flow in a logical way
asaniDev 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
removed redundant code, added code to stop alarm if runnng
- Loading branch information
commit 24540869f0ca71af8a7d9269eb77d882eded999e
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 |
|---|---|---|
|
|
@@ -5,30 +5,37 @@ let changeBgColor = false; | |
| function setAlarm() { | ||
| inputTime = Number(document.querySelector("#alarmSet").value); | ||
|
|
||
| if (Number.isInteger(inputTime) && inputTime >= 0) { | ||
| if (inputTime === 10) { | ||
| changeBgColor = true; | ||
| } else if (inputTime === 0) { | ||
| displayTime(inputTime); | ||
| playAlarm(); | ||
| document.querySelector("#alarmSet").value = ""; | ||
| } | ||
| if (!Number.isInteger(inputTime) || inputTime < 0) { | ||
| return; | ||
| } | ||
| if (inputTime === 10) { | ||
| changeBgColor = true; | ||
| } else if (inputTime === 0) { | ||
| displayTime(inputTime); | ||
| if (timer) { | ||
| clearInterval(timer); | ||
| timer = null; | ||
| } | ||
| timer = setInterval(countDown, 1000); | ||
| playAlarm(); | ||
| document.querySelector("#alarmSet").reset(); | ||
| } | ||
| displayTime(inputTime); | ||
| if (typeof audio !== "undefined" && audio) { | ||
| audio.pause(); | ||
| try { | ||
| audio.currentTime = 0; | ||
| } catch (e) {} | ||
| audio.loop = false; // disable looping if it was set | ||
| } | ||
| if (timer) { | ||
| clearInterval(timer); | ||
| } | ||
| timer = setInterval(countDown, 1000); | ||
| } | ||
|
Comment on lines
+13
to
+21
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. When Consider organising the code in the following maner: |
||
|
|
||
| function displayTime(totalTime) { | ||
| const seconds = totalTime % 60; | ||
| const minutes = (totalTime - seconds) / 60; | ||
| const timeLeft = document.querySelector("#timeRemaining"); | ||
| timeLeft.innerText = `Time Remaining: ${minutes | ||
| const timeLeft = document.querySelector("#theTime"); | ||
| timeLeft.innerText = `${minutes.toString().padStart(2, 0)}:${seconds | ||
| .toString() | ||
| .padStart(2, 0)}:${seconds.toString().padStart(2, 0)}`; | ||
| .padStart(2, 0)}`; | ||
| } | ||
|
|
||
| function countDown() { | ||
|
|
@@ -83,31 +90,3 @@ function pauseAlarm() { | |
| } | ||
|
|
||
| window.onload = setup; | ||
|
|
||
| /* | ||
| Given the user has entered a number in the input field When the user clicks the “Set Alarm” button Then the “Time Remaining” title should update to show the entered number in mm:ss format | ||
| take value from in input field and store it in a variable inputTime | ||
| check inputTime value is within the accepted range? | ||
| take variable inputTime and display it in time remaining section | ||
|
|
||
|
|
||
| Given the alarm is set with a valid time When one second passes Then the “Time Remaining” title should decrement by 1 second | ||
| the the value for time remaining | ||
| check its a valid time (greater than 00:00) | ||
| decrease value of time remaining by 1 sec for each sec that passes | ||
|
|
||
| Given the alarm is set with a time of 00:00 When the timer reaches 00:00 Then the alarm sound should play continuously | ||
| check time remaining, if it is equal to 00:00 then sound alarm | ||
|
|
||
|
|
||
| Given the alarm sound is currently playing When the user clicks the “Stop Alarm” button Then the alarm sound should stop playing | ||
| check if stop alarm button has been pressed | ||
| if true then check if alarm sound is playing then stop alarm sound if true | ||
|
|
||
| Given the alarm is set with a time of 00:10 When the timer reaches 00:00 Then the background color should change And the alarm sound should play | ||
| if inputTime is 00:10 and timer reaches 0 the change background color | ||
| play alarm sound | ||
|
|
||
| Given the user has not set an alarm When the page first loads Then the “Time Remaining” title should show 00:00 And no alarm sound should play | ||
| when page loads time remaining should 0 and no alarm sound should play | ||
| */ | ||
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.
Does the app need to execute the code on line 20 when
inputTimeis0?Can you figure out what would happen when line 20 is executed when
inputTimeis0? Even though the side-effect is almost unnoticeable, it is important we (as a programmer) recognise what our code do exactly.