-
-
Notifications
You must be signed in to change notification settings - Fork 327
London| 26-ITP-May | Mandip Sanger | Sprint 3 | Alarm Clock #1435
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
Open
mandipsanger
wants to merge
8
commits into
CodeYourFuture:main
Choose a base branch
from
mandipsanger:Sprint-3
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+85
−39
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8cd6d48
alarmclock
mandipsanger 85a4ac8
validation for alarm clock
mandipsanger 0e8ddbe
fix errors
mandipsanger 2e1477a
fix errors
mandipsanger 782f99c
alarmclock
mandipsanger f848cae
add validation
mandipsanger ece8ebf
add pause alarm
mandipsanger 23c4383
adding html and css file
mandipsanger 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,25 +1,80 @@ | ||
| function setAlarm() {} | ||
| let timer; | ||
|
|
||
| // DO NOT EDIT BELOW HERE | ||
| const audio = new Audio("alarmsound.mp3"); | ||
|
|
||
| var audio = new Audio("alarmsound.mp3"); | ||
| function setAlarm() { | ||
| const form = document.getElementById("ShowForm"); | ||
| const input = document.getElementById("alarmSet"); | ||
| const heading = document.getElementById("timeRemaining"); | ||
|
|
||
| function setup() { | ||
| document.getElementById("set").addEventListener("click", () => { | ||
| setAlarm(); | ||
| }); | ||
| // Step 1: retrieve input value | ||
| const inputValue = input.value; | ||
|
|
||
| // Step 2: validate if input is a number | ||
| const numberValue = Number(inputValue); | ||
|
|
||
| // Step 3: validate if it is an integer | ||
| if (!Number.isInteger(numberValue)) { | ||
| alert("Only enter an integer value."); | ||
| return; | ||
| } | ||
|
|
||
| // Step 4: validate if it is greater than 0 | ||
| if (numberValue <= 0) { | ||
| alert("Only enter a number which is bigger than 0."); | ||
| return; | ||
| } | ||
|
|
||
| let timeRemaining = numberValue; | ||
|
|
||
| function formatTime(totalSeconds) { | ||
| const minutes = Math.floor(totalSeconds / 60); | ||
| const seconds = totalSeconds % 60; | ||
|
|
||
| return `Time Remaining: ${String(minutes).padStart(2, "0")}:${String( | ||
| seconds | ||
| ).padStart(2, "0")}`; | ||
| } | ||
|
|
||
| // Show starting time | ||
| heading.innerText = formatTime(timeRemaining); | ||
|
|
||
| document.getElementById("stop").addEventListener("click", () => { | ||
| pauseAlarm(); | ||
| }); | ||
| // Stop an existing timer | ||
| clearInterval(timer); | ||
| pauseAlarm(); | ||
|
|
||
|
mandipsanger marked this conversation as resolved.
|
||
| timer = setInterval(() => { | ||
| timeRemaining--; | ||
|
|
||
| if (timeRemaining <= 0) { | ||
| timeRemaining = 0; | ||
| heading.innerText = formatTime(timeRemaining); | ||
|
|
||
| clearInterval(timer); | ||
| playAlarm(); | ||
| return; | ||
| } | ||
|
|
||
| heading.innerText = formatTime(timeRemaining); | ||
| }, 1000); | ||
| } | ||
|
|
||
| // Play alarm | ||
| function playAlarm() { | ||
| audio.play(); | ||
| } | ||
|
|
||
| // Stop alarm | ||
| function pauseAlarm() { | ||
| audio.pause(); | ||
| audio.currentTime = 0; | ||
| } | ||
|
|
||
| // Setup buttons | ||
| function setup() { | ||
| document.getElementById("set").addEventListener("click", setAlarm); | ||
|
|
||
| document.getElementById("stop").addEventListener("click", pauseAlarm); | ||
| } | ||
|
|
||
| window.onload = setup; | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,17 +4,24 @@ | |
| <meta charset="utf-8" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
| <link rel="stylesheet" href="style.css" /> | ||
| <title>Title here</title> | ||
| <title>Alarm Clock</title> | ||
| </head> | ||
|
|
||
| <form id="showForm"> | ||
| <input type="text" id="showName" placeholder="Enter show name"> | ||
| <button type="submit">Search</button> | ||
| </form> | ||
|
|
||
| <div id="episodes"></div>> | ||
| <body> | ||
| <div class="centre"> | ||
| <h1 id="timeRemaining">Time Remaining: 00:00</h1> | ||
| <label for="alarmSet">Set time to:</label> | ||
| <input id="alarmSet" type="number" /> | ||
| <label for="alarmSet">Set time in seconds:</label> | ||
| <input id="alarmSet" type="number" min="1" step="1" placeholder="Enter seconds" /> | ||
|
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. Note: Without a form, the browser won't check the input against the constraints Change is optional. |
||
|
|
||
| <button id="set" type="button">Set Alarm</button> | ||
| <button id="stop" type="button">Stop Alarm</button> | ||
| </div> | ||
| <script src="alarmclock.js"></script> | ||
| </body> | ||
| </html> | ||
| </html> | ||
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
Oops, something went wrong.
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.
Notes:
Could probably just check both conditions in the one if-statement and then change the message to mention "... positive integer".
While
alert()is convenient to use, it is not a user-friendly way to notify the user an error.No change needed.
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.
yes i made changes but it is still showing to do list I have replaced the orignial file and pushed it through, but I think I have made both under sprint 3 so thats why its showing like this. any idea how can i sort it out usually when I replace the original file from github it goes away but this time it didnt. May be becuase they both in sprint 3. Are you able to help otherwise its failing the checks