Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion Sprint-3/alarmclock/alarmclock.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@
function setAlarm() {}
// ## How the clock should work

// When you click the `Set Alarm` button the counter at the top of the screen should change to the number you entered in the `input` field. For example, if the `input` field says `10` then the title should say `Time Remaining: 00:10`.

// Every one second the title should count down by one.

// When the `Time Remaining` reaches `00:00` the alarm should play a sound. You can make the sound happen by using `playAlarm()`.

// You can stop the alarm sound by pressing the `Stop Alarm` button.

//
const alarmInput = document.querySelector("#alarmSet");
const setButton = document.querySelector("#set");
const timeRemaining = document.querySelector("#timeRemaining");
function setAlarm() {
let totalSeconds = Number(alarmInput.value);
Comment thread
cjyuan marked this conversation as resolved.
Resolved
const timer = setInterval(() => {
totalSeconds--;
const minutes = String(Math.floor(totalSeconds / 60)).padStart(2, "0");
const seconds = String(Math.floor(totalSeconds % 60)).padStart(2, "0");
const remainingTime = minutes + ":" + seconds;
timeRemaining.innerText = `Time Remaining:${remainingTime}`;
if (totalSeconds === 0) {
clearInterval(timer);
playAlarm();
}
}, 1000);
Comment on lines +39 to 47

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this change, there will always be a one second delay before the alarm sound.
Could you find a way to get rid the one second delay?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I Have fixed this now. THank you

}

setButton.addEventListener("click", setAlarm);
// DO NOT EDIT BELOW HERE

var audio = new Audio("alarmsound.mp3");
Expand Down
4 changes: 2 additions & 2 deletions Sprint-3/alarmclock/index.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<!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">
Expand Down
9 changes: 9 additions & 0 deletions Sprint-3/alarmclock/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,13 @@

h1 {
text-align: center;
color: rgb(117, 13, 13);
}
body {
background-color: rgb(197, 107, 122);
}
button {
background-color: rgb(151, 77, 114);
color: white;
padding: 10px;
}
Loading