Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
32 changes: 30 additions & 2 deletions Sprint-3/alarmclock/alarmclock.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,35 @@
function setAlarm() {}
function setAlarm() {
const input = document.getElementById("alarmSet");
const heading = document.getElementById("timeRemaining");
let timeRemaining = Number(input.value);

function updateHeading() {
const minutes = Math.floor(timeRemaining / 60);
const seconds = timeRemaining % 60;
const formattedMinutes = String(minutes).padStart(2, "0");
const formattedSeconds = String(seconds).padStart(2, "0");
heading.innerText =
`Time Remaining: ${formattedMinutes}:${formattedSeconds}`;
}
updateHeading();
// If the alarm is set to 00:00
if (timeRemaining === 0) {
playAlarm();
return;
}

const timer = setInterval(() => {
timeRemaining--;
updateHeading();
// When the countdown reaches zero
if (timeRemaining === 0) {
clearInterval(timer);
playAlarm();
document.body.style.backgroundColor = "lightcoral";
}
}, 1000);
}
// DO NOT EDIT BELOW HERE

var audio = new Audio("alarmsound.mp3");

function setup() {
Expand Down
2 changes: 1 addition & 1 deletion Sprint-3/alarmclock/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>Alarm Clock App</title>
</head>
<body>
<div class="centre">
Expand Down
2 changes: 1 addition & 1 deletion Sprint-3/alarmclock/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@

h1 {
text-align: center;
}
}
Loading