Skip to content
Closed
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
54 changes: 53 additions & 1 deletion Sprint-3/alarmclock/alarmclock.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,57 @@
function setAlarm() {}
let countDown;
let remainingSeconds = 0;

function setAlarm() {
let timeRemaining = document.getElementById("timeRemaining");
let alarmSet = document.getElementById("alarmSet").value;

remainingSeconds = parseInt(alarmSet);

if (isNaN(remainingSeconds) || remainingSeconds <= 0) {
alert("please enter a value greater than zero!");
return;
}

if (remainingSeconds > 86400) {
alert("Please enter a time less than 24 hourse (86,400)");
return;
}
displayTime();

if (countDown) {
clearInterval(countDown);
}
countDown = setInterval(timer, 1000);
}

function displayTime() {
let timeRemaining = document.getElementById("timeRemaining");
let hour = Math.floor(remainingSeconds / 3600);
let minutes = Math.floor((remainingSeconds % 3600) / 60);
let seconds = Math.floor(remainingSeconds % 60);

if (minutes < 10) {
minutes = "0" + minutes;
}
if (seconds < 10) {
seconds = "0" + seconds;
}

if (hour > 0) {
timeRemaining.textContent = `Time Remaining: ${hour}:${minutes}:${seconds}`;
} else {
timeRemaining.textContent = `Time Remaining: ${minutes}:${seconds}`;
}
}

function timer() {
remainingSeconds--;
displayTime();
if (remainingSeconds <= 0) {
clearInterval(countDown);
playAlarm();
}
}
// DO NOT EDIT BELOW HERE

var audio = new Audio("alarmsound.mp3");
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</title>
</head>
<body>
<div class="centre">
Expand Down