-
-
Notifications
You must be signed in to change notification settings - Fork 279
GLASGOW | Jan-26-ITP | Prakash Dcosta | Sprint 3 | Alarm Clock #1114
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 2 commits
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,4 +1,36 @@ | ||
| function setAlarm() {} | ||
| let timeRemaining; | ||
| let timerId; | ||
| function setAlarm() { | ||
| const input = document.getElementById("alarmSet").value; | ||
| timeRemaining = Number(input); | ||
|
|
||
| clearInterval(timerId); | ||
|
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
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 |
||
|
|
||
| updateDisplay(); | ||
|
|
||
| timerId = setInterval(() => { | ||
| timeRemaining--; | ||
| updateDisplay(); | ||
|
|
||
| if (timeRemaining <= 0) { | ||
| timeRemaining = 0; | ||
| updateDisplay(); | ||
| clearInterval(timerId); | ||
| playAlarm(); | ||
| } | ||
| }, 1000); | ||
| } | ||
| function updateDisplay() { | ||
| const display = document.getElementById("timeRemaining"); | ||
|
|
||
| const minutes = Math.floor(timeRemaining / 60); | ||
| const seconds = timeRemaining % 60; | ||
|
|
||
| const formattedMinutes = String(minutes).padStart(2, "0"); | ||
| const formattedSeconds = String(seconds).padStart(2, "0"); | ||
|
|
||
| display.textContent = `Time Remaining: ${formattedMinutes}:${formattedSeconds}`; | ||
| } | ||
|
|
||
| // DO NOT EDIT BELOW HERE | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ | |
| <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>AlarmClock</title> | ||
|
||
| </head> | ||
| <body> | ||
| <div class="centre"> | ||
|
|
||
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.
Yes. I see it is accepting negative and null inputs. I have made the change. Thank you for pointing it out