generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 179
Karla Grajales | Module-Data-Groups | sprint-3 Alarm clock app #293
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 all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
5aa2cff
added new audio to run and stop the time
Grajales-K b1ef622
added container to the alarm and centred and color style
Grajales-K 613e833
added sound music for buttons effects and place holder
Grajales-K b66a14b
update music sound and package-lock.json
Grajales-K 4984414
update package
Grajales-K 69f0ba8
catch the input and alert to write valid number
Grajales-K 746c5d6
added function for timer and display the remaining time
Grajales-K 7d6ca47
setInterval function to manipulate the timer
Grajales-K b8e5a1e
added emojis to the alert and all test passed
Grajales-K d993596
added favicon for browser
Grajales-K 50337cc
update the title and added favicon to the web
Grajales-K ebc091e
update input with min value to restric numbers negatives
Grajales-K ecf16a5
added new img for browser
Grajales-K 6a3e47a
fixed the count timing to play the sound at 00:00
Grajales-K 2a457b7
added placeholder in th html favicon and description
Grajales-K 1d7c83b
fixed min on input html
Grajales-K 38da6ae
Merge pull request #1 from Grajales-K/alarm-tester
Grajales-K 18e8526
Recovered merge changes
Grajales-K 1370231
Fix: Time displayer shows 00:00 at zero
Grajales-K 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,8 +1,62 @@ | ||
| function setAlarm() {} | ||
| let countdown; // Declare countdown globally to make it accessible | ||
|
|
||
| // DO NOT EDIT BELOW HERE | ||
| function setAlarm() { | ||
| // Clear any previous timer to prevent multiple timers running simultaneously | ||
| clearInterval(countdown); | ||
|
|
||
| // Get the value entered by the user in the input field and convert it to an integer | ||
| let inputTime = parseInt(document.getElementById("alarmSet").value); | ||
|
|
||
| // If the input is not a valid number or is less than or equal to 0, show an alert and stop execution | ||
| if (isNaN(inputTime) || inputTime <= 0) { | ||
| alert("Please type or select your time 👇⏰"); | ||
| return; | ||
| } | ||
|
|
||
| // Store the remaining time for the countdown | ||
| let timeRemaining = inputTime; | ||
|
|
||
| /** | ||
| * Function to format the time into "MM:SS" format | ||
| * @param {number} seconds - The number of seconds to be formatted | ||
| * @returns {string} - The formatted time in the form "Time Remaining: MM:SS" | ||
| */ | ||
| function formatTime(seconds) { | ||
| // Calculate minutes and remaining seconds | ||
| const minutes = Math.floor(seconds / 60); | ||
| const remainingSeconds = seconds % 60; | ||
|
|
||
| // Return the formatted time as a string | ||
| return `Time Remaining: ${minutes | ||
| .toString() | ||
| .padStart(2, "0")}:${remainingSeconds.toString().padStart(2, "0")}`; | ||
| } | ||
|
|
||
| var audio = new Audio("alarmsound.mp3"); | ||
| // Update the time display on the page with the initial time | ||
| document.getElementById("timeRemaining").textContent = | ||
| formatTime(timeRemaining); | ||
|
|
||
| // Start the countdown timer to update the time every second | ||
| countdown = setInterval(function () { | ||
| // Otherwise, decrease the remaining time by 1 second | ||
| timeRemaining--; | ||
|
|
||
| // If the time reaches 0, stop the countdown and play the alarm | ||
| if (timeRemaining <= 0) { | ||
| clearInterval(countdown); // Stop the countdown timer | ||
| document.getElementById("timeRemaining").textContent = formatTime(0); // Ensure "00:00" is displayed | ||
| playAlarm(); // Play the alarm sound | ||
| } else { | ||
| // Update the time display on the page with the updated time | ||
| document.getElementById("timeRemaining").textContent = | ||
| formatTime(timeRemaining); | ||
|
Comment on lines
+47
to
+52
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.
|
||
| } | ||
| }, 1000); // The timer runs every 1000 milliseconds (1 second) | ||
| } | ||
|
|
||
| // DO NOT EDIT BELOW HERE | ||
| let soundAlarm = new Audio("trebolClan.mp3"); | ||
| let SoundStop = new Audio("stopAlarm.mp3"); | ||
|
|
||
| function setup() { | ||
| document.getElementById("set").addEventListener("click", () => { | ||
|
|
@@ -15,11 +69,14 @@ function setup() { | |
| } | ||
|
|
||
| function playAlarm() { | ||
| audio.play(); | ||
| soundAlarm.play(); | ||
| } | ||
|
|
||
| function pauseAlarm() { | ||
| audio.pause(); | ||
| clearInterval(countdown); | ||
| soundAlarm.pause(); | ||
| soundAlarm.currentTime = 0; | ||
| SoundStop.play(); | ||
| } | ||
|
|
||
| window.onload = setup; | ||
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Binary file not shown.
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,15 +1,71 @@ | ||
| /* General Styles */ | ||
| body { | ||
| background-color: #f7f3f2; | ||
| color: #333; | ||
| font-family: Arial, sans-serif; | ||
| margin: 0; | ||
| padding: 0; | ||
| display: flex; | ||
| justify-content: center; | ||
| align-items: center; | ||
| height: 100vh; | ||
| } | ||
|
|
||
| /* Centered Container */ | ||
| .centre { | ||
| position: fixed; | ||
| top: 50%; | ||
| left: 50%; | ||
| -webkit-transform: translate(-50%, -50%); | ||
| transform: translate(-50%, -50%); | ||
| background: #ffffff; | ||
| padding: 20px 40px; | ||
| border-radius: 12px; | ||
| box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); | ||
| text-align: center; | ||
|
|
||
| } | ||
|
|
||
| /* Input Field */ | ||
| #alarmSet { | ||
| margin: 20px; | ||
| margin: 15px 0; | ||
| padding: 10px; | ||
| border: 1px solid #ccc; | ||
| border-radius: 6px; | ||
| font-size: 16px; | ||
| width: 80%; | ||
| max-width: 300px; | ||
| box-sizing: border-box; | ||
| } | ||
|
|
||
| h1 { | ||
| text-align: center; | ||
| #alarmSet::placeholder { | ||
| color: #888; | ||
| font-style: italic; | ||
| font-family: 'Arial', sans-serif; | ||
| font-size: 16px; | ||
| } | ||
|
|
||
| /* Button */ | ||
| button { | ||
| background-color: #6c63ff; | ||
| color: white; | ||
| border: none; | ||
| border-radius: 6px; | ||
| padding: 10px 20px; | ||
| font-size: 16px; | ||
| cursor: pointer; | ||
| transition: background-color 0.3s ease, transform 0.2s ease; | ||
| } | ||
|
|
||
| button:hover { | ||
| background-color: #5753d3; | ||
| transform: translateY(-2px); | ||
| } | ||
|
|
||
| button:active { | ||
| background-color: #4b47b0; | ||
| transform: translateY(0); | ||
| } | ||
|
|
||
| /* Headings */ | ||
| h1 { | ||
| font-size: 24px; | ||
| font-weight: bold; | ||
| margin-bottom: 10px; | ||
| color: #6c63ff; | ||
| } |
Binary file not shown.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.