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
31 changes: 30 additions & 1 deletion Sprint-3/alarmclock/alarmclock.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,33 @@
function setAlarm() {}
function setAlarm() {
const alarmSet = document.getElementById("alarmSet").value;
const timeRemaining = document.getElementById("timeRemaining");

let totalSeconds = parseInt(alarmSet);

let countdown = setInterval(() => {
let minutes = Math.floor(totalSeconds / 60);
let seconds = totalSeconds % 60;

timeRemaining.textContent = `Time Remaining: ${String(
minutes
).padStart(2, "0")}:${String(seconds).padStart(2, "0")}`;

if (totalSeconds <= 0) {
clearInterval(countdown);
playAlarm();
let flash = setInterval(() => {
document.body.style.backgroundColor =
document.body.style.backgroundColor === "red" ? "white" : "red";
}, 500);
setTimeout(() => {
clearInterval(flash);
document.body.style.backgroundColor = "white";
}, 5000);
}

totalSeconds--;
}, 1000);
}

// DO NOT EDIT BELOW HERE

Expand Down
11 changes: 6 additions & 5 deletions Sprint-3/alarmclock/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@
<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>
<input id="alarmSet" type="number" min="1" />
<div class="buttons">
<button id="set" type="button">Set Alarm</button>
<button id="stop" type="button">Stop Alarm</button>
</div>
</div>
<script src="alarmclock.js"></script>
</body>
Expand Down