Skip to content
Closed
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
29 changes: 28 additions & 1 deletion Sprint-3/alarmclock/alarmclock.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,31 @@
function setAlarm() {}
function setAlarm() {
const input = document.getElementById("alarmSet");
const heading = document.getElementById("timeRemaining");
let seconds = Number(input.value);

function updateDisplay(remainingSeconds) {
const minutes = Math.floor(remainingSeconds / 60);
const secs = remainingSeconds % 60;
const formattedTime = `${String(minutes).padStart(2, "0")}:${String(secs).padStart(2, "0")}`;
heading.textContent = `Time Remaining: ${formattedTime}`;
document.body.style.backgroundColor = "";
}

// Set initial display
updateDisplay(seconds);

// Start countdown
const timerId = setInterval(() => {
seconds--;
updateDisplay(seconds);

if (seconds <= 0) {
clearInterval(timerId);
playAlarm();
document.body.style.backgroundColor = "red";
}
}, 1000);
}

// DO NOT EDIT BELOW HERE

Expand Down
7 changes: 4 additions & 3 deletions Sprint-3/alarmclock/index.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
<!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>
<link rel="icon" href="" />
<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" />
<input id="alarmSet" type="number" min="1" />

<button id="set" type="button">Set Alarm</button>
<button id="stop" type="button">Stop Alarm</button>
Expand Down