Skip to content
36 changes: 35 additions & 1 deletion Sprint-3/alarmclock/alarmclock.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,39 @@
function setAlarm() {}
const userInput = document.querySelector("#alarmSet");
const timeRemaining = document.querySelector("#timeRemaining");
const stop = document.querySelector("#stop");
let totalSeconds = 0;

function main() {
document.getElementById("alarmSet").addEventListener("click", counterUpdate);
document.getElementById("alarmSet").addEventListener("keyup", counterUpdate);
}

function counterUpdate() {
const userInputValue = userInput.value;
if (userInputValue >= 0) {
totalSeconds = userInputValue;
displyUpdate();
}
}

function displyUpdate() {
const minutes = Math.floor(totalSeconds / 60);
const seconds = totalSeconds % 60;
timeRemaining.innerText = `Time Remaining: ${minutes.toString().padStart(2, "0")}:${seconds.toString().padStart(2, "0")}`;
}

function setAlarm() {
const interval = setInterval(() => {
totalSeconds--;
displyUpdate();
if (totalSeconds <= 0) {
clearInterval(interval);
userInput.value = "";
playAlarm();
}
}, 1000);
}
main();
// 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
Loading