-
-
Notifications
You must be signed in to change notification settings - Fork 280
Manchester | 26-ITP-jan | Liban Jama | Sprint 3 | Alarm Clock #1075
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
ba1d60c
0bcf364
16e648e
22008f8
fc50e53
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,34 @@ | ||
| function setAlarm() {} | ||
| var audio = new Audio("alarmsound.mp3"); | ||
|
|
||
| // DO NOT EDIT BELOW HERE | ||
| let countdown; | ||
|
|
||
| var audio = new Audio("alarmsound.mp3"); | ||
| function formatTime(seconds) { | ||
| let mins = Math.floor(seconds / 60); | ||
| let secs = seconds % 60; | ||
| return String(mins).padStart(2, "0") + ":" + String(secs).padStart(2, "0"); | ||
| } | ||
|
|
||
| function setAlarm() { | ||
| let seconds = parseInt(document.getElementById("alarmSet").value); | ||
| if (!Number.isFinite(seconds) || seconds < 1) { | ||
| throw new Error("Please enter a valid number greater than 0"); | ||
| } | ||
| clearInterval(countdown); | ||
|
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. Nice clearing of the interval to ensure only one countdown is running at all times
Author
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. thank you |
||
| document.getElementById("timeRemaining").textContent = | ||
| "Time Remaining: " + formatTime(seconds); | ||
|
|
||
| countdown = setInterval(() => { | ||
| seconds--; | ||
| document.getElementById("timeRemaining").textContent = | ||
| "Time Remaining: " + formatTime(seconds); | ||
|
|
||
| if (seconds <= 0) { | ||
| clearInterval(countdown); | ||
| document.body.classList.add("alarm-finished"); | ||
| playAlarm(); | ||
| } | ||
| }, 1000); | ||
| } | ||
|
|
||
| function setup() { | ||
| document.getElementById("set").addEventListener("click", () => { | ||
|
|
@@ -19,7 +45,9 @@ function playAlarm() { | |
| } | ||
|
|
||
| function pauseAlarm() { | ||
| clearInterval(countdown); | ||
| audio.pause(); | ||
| document.body.classList.remove("alarm-finished"); | ||
| } | ||
|
|
||
| window.onload = setup; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,21 @@ | ||
| <!DOCTYPE html> | ||
| <!doctype html> | ||
| <html lang="en"> | ||
| <head> | ||
| <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 app</title> | ||
| </head> | ||
| <body> | ||
| <div class="centre"> | ||
| <h1 id="timeRemaining">Time Remaining: 00:00</h1> | ||
| <label for="alarmSet">Set time to:</label> | ||
| <input id="alarmSet" type="number" /> | ||
|
|
||
| <button id="set" type="button">Set Alarm</button> | ||
| <button id="stop" type="button">Stop Alarm</button> | ||
| <div class="button-group"> | ||
| <button id="set" type="button">Set Alarm</button> | ||
| <button id="stop" type="button">Stop Alarm</button> | ||
| </div> | ||
| </div> | ||
|
Comment on lines
+15
to
+19
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. How can you format the code to indicate more clearly the hierachy of HTML elements (what is a children of what)
Author
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. formatting fixed |
||
| <script src="alarmclock.js"></script> | ||
| </body> | ||
|
|
||
|
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. The alarm clock looks really nice now. Good job |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,108 @@ | ||
| * { | ||
| box-sizing: border-box; | ||
| } | ||
|
|
||
| body { | ||
| margin: 0; | ||
| font-family: Arial, sans-serif; | ||
| min-height: 100vh; | ||
| display: flex; | ||
| justify-content: center; | ||
| align-items: center; | ||
| background: linear-gradient(90deg, #fcff9e 0%, #c67700 100%); | ||
| transition: background 0.4s ease; | ||
| } | ||
|
|
||
| .alarm-finished { | ||
| background: linear-gradient(90deg, #FC466B 0%, #3F5EFB 100%); | ||
| animation: flashBg 0.6s infinite alternate; | ||
| } | ||
| @keyframes flashBg { | ||
| 0% { | ||
| background: linear-gradient(90deg, #FC466B 0%, #3F5EFB 100%); | ||
| } | ||
| 100% { | ||
| background: linear-gradient(90deg, #fcff9e 0%, #c67700 100%); | ||
| } | ||
| } | ||
|
|
||
| .centre { | ||
| position: fixed; | ||
| top: 50%; | ||
| left: 50%; | ||
| -webkit-transform: translate(-50%, -50%); | ||
| transform: translate(-50%, -50%); | ||
| width: 360px; | ||
| padding: 26px; | ||
| background: #ffffff; | ||
| border-radius: 20px; | ||
| box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2); | ||
| text-align: center; | ||
| } | ||
|
|
||
| label { | ||
| display: block; | ||
| margin-bottom: 10px; | ||
| font-size: 15px; | ||
| color: #555; | ||
| } | ||
|
|
||
| #timeRemaining { | ||
| margin: 0 0 22px; | ||
| font-size: 30px; | ||
| font-weight: bold; | ||
| color: #333; | ||
| } | ||
|
|
||
| label { | ||
| display: block; | ||
| margin-bottom: 10px; | ||
| font-size: 15px; | ||
| color: #555; | ||
| } | ||
|
|
||
| #alarmSet { | ||
| margin: 20px; | ||
| width: 100%; | ||
| padding: 12px; | ||
| font-size: 16px; | ||
| border: 2px solid #ddd; | ||
| border-radius: 12px; | ||
| outline: none; | ||
| margin-bottom: 18px; | ||
| transition: 0.2s; | ||
| } | ||
|
|
||
| h1 { | ||
| text-align: center; | ||
| #alarmSet:focus { | ||
| border-color: #667eea; | ||
| box-shadow: 0 0 6px rgba(102, 126, 234, 0.4); | ||
| } | ||
|
|
||
| .button-group { | ||
| display: flex; | ||
| gap: 12px; | ||
| } | ||
|
|
||
| button { | ||
| flex: 1; | ||
| padding: 12px; | ||
| font-size: 15px; | ||
| border: none; | ||
| border-radius: 12px; | ||
| cursor: pointer; | ||
| color: white; | ||
| font-weight: bold; | ||
| transition: transform 0.15s ease, box-shadow 0.15s ease; | ||
| } | ||
|
|
||
| #set { | ||
| background: #4CAF50; | ||
| } | ||
|
|
||
| #set:hover { | ||
| background: #43a047; | ||
| transform: translateY(-2px); | ||
| } | ||
|
|
||
| #stop { | ||
| background: #f44336; | ||
| } | ||
|
|
||
| #stop:hover { | ||
| background: #e53935; | ||
| transform: translateY(-2px); | ||
| } |
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.
What happens when the user enters a negative number or a string value?
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.
Updated to throw an error