-
-
Notifications
You must be signed in to change notification settings - Fork 278
London | 26-ITP-Jan | Karla Grajales | Sprint 3 | Alarm Clock App #1183
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 all commits
d3adbf9
a067260
97a40d0
14a0278
3b04b19
13ef67d
e89fc7d
088efa0
2e8d9f5
b0b40a3
b33fd6a
063968e
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,8 +1,59 @@ | ||
| function setAlarm() {} | ||
| let countdown; | ||
|
|
||
| function setAlarm() { | ||
| clearInterval(countdown); | ||
| document.body.style.backgroundColor = "white"; | ||
|
Comment on lines
+4
to
+5
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. Currently when starting a new countdown, the application does not always return to a clean initial state, Hint: a user may not click the "Stop" button first before starting a new count down. You can also consider introducing a dedicated reset function to return the app to a clean initial state to help ensure consistency. There are few places in this script you can call this reset function instead of repeating the reset logic. |
||
|
|
||
| let inputTime = Number(document.getElementById("alarmSet").value); | ||
|
|
||
| if (isNaN(inputTime) || inputTime <= 0) { | ||
| alert("Please type or select your time 👇⏰"); | ||
| return; | ||
| } | ||
|
Comment on lines
+7
to
+12
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. What type of numbers should |
||
|
|
||
| updateDisplay(inputTime); | ||
|
|
||
| countdown = setInterval(() => { | ||
| inputTime--; | ||
|
|
||
| if (inputTime <= 0) { | ||
| clearInterval(countdown); | ||
| updateDisplay(0); | ||
| playAlarm(); | ||
|
|
||
| let repetitions = 0; | ||
| countdown = setInterval(() => { | ||
| document.body.style.backgroundColor = `rgb( | ||
| ${Math.floor(Math.random() * 256)}, | ||
| ${Math.floor(Math.random() * 256)}, | ||
| ${Math.floor(Math.random() * 256)})`; | ||
| repetitions++; | ||
|
|
||
| if (repetitions > 100) { | ||
| clearInterval(countdown); | ||
| } | ||
|
Comment on lines
+24
to
+34
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. It is best practice to separate presentation logic from application logic. Note: CSS random() function is still in experimental stage. With pure CSS, we can only cycle through a pre-defined set of colors (e.g. https://codepen.io/beben-koben/pen/eYPNew) If you are implementing this purely in CSS, you can consider defining a CSS class, and use |
||
| }, 200); | ||
| } else { | ||
| updateDisplay(inputTime); | ||
| } | ||
| }, 1000); | ||
| } | ||
|
|
||
| function updateDisplay(seconds) { | ||
| let minutes = Math.floor(seconds / 60); | ||
| let remainingSeconds = seconds % 60; | ||
|
|
||
| let display = `Time Remaining: ${minutes | ||
| .toString() | ||
| .padStart(2, "0")}:${remainingSeconds.toString().padStart(2, "0")}`; | ||
|
Comment on lines
+46
to
+48
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. Having a long expression within a template string literal can make the code harder to read. |
||
|
|
||
| document.getElementById("timeRemaining").innerText = display; | ||
| } | ||
|
|
||
| // DO NOT EDIT BELOW HERE | ||
|
|
||
| var audio = new Audio("alarmsound.mp3"); | ||
| let audio = new Audio("assets/trebolClan.mp3"); | ||
| let stopAudio = new Audio("assets/stopAlarm.mp3"); | ||
|
|
||
| function setup() { | ||
| document.getElementById("set").addEventListener("click", () => { | ||
|
|
@@ -20,6 +71,9 @@ function playAlarm() { | |
|
|
||
| function pauseAlarm() { | ||
| audio.pause(); | ||
| stopAudio.play(); | ||
| audio.currentTime = 0; | ||
| clearInterval(countdown); | ||
| } | ||
|
|
||
| window.onload = setup; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,65 @@ | ||
|
|
||
|
|
||
| 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; | ||
| } | ||
|
|
||
| .centre { | ||
| position: fixed; | ||
| top: 50%; | ||
| left: 50%; | ||
| -webkit-transform: translate(-50%, -50%); | ||
| transform: translate(-50%, -50%); | ||
| padding: 2rem 2rem; | ||
| border-radius: 12px; | ||
| box-shadow: 0 4px 6px rgba(0, 0, 0, 0.8); | ||
| text-align: center; | ||
| } | ||
|
|
||
| /* Input Field */ | ||
| #alarmSet { | ||
| margin: 20px; | ||
| margin: 1rem ; | ||
| padding: 1rem; | ||
| border: 1px solid #ccc; | ||
| border-radius: 6px; | ||
| font-size: 1rem; | ||
| max-width: 300px; | ||
| box-sizing: border-box; | ||
| } | ||
|
|
||
| #alarmSet::placeholder { | ||
| color: #888; | ||
| font-style: italic; | ||
| font-family: 'Arial', sans-serif; | ||
| font-size: 0.8rem; | ||
| } | ||
|
|
||
| h1 { | ||
| text-align: center; | ||
| } | ||
|
|
||
| /* 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: #dedee8; | ||
| color: #6c63ff; | ||
| transform: translateY(-2px); | ||
| } | ||
|
|
||
| button:active { | ||
| background-color: #4b47b0; | ||
| transform: translateY(0); | ||
| } |
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.
Consider renaming
countdowntocountdownIntervalorintervalIdsince this stores the interval ID, not the countdown value.