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
29 changes: 26 additions & 3 deletions Sprint-3/alarmclock/alarmclock.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,30 @@
function setAlarm() {}
var audio = new Audio("alarmsound.mp3");

// DO NOT EDIT BELOW HERE
let countdown;

var audio = new Audio("alarmsound.mp3");
function formatTime(seconds) {
let mins = Math.floor(seconds / 60);
let secs = seconds % 60;
return String(mins).padStart(2, "0") + ":" + String(secs).padStart(2, "0");
}

function setAlarm() {
let seconds = parseInt(document.getElementById("alarmSet").value);
clearInterval(countdown);
document.getElementById("timeRemaining").textContent =
"Time Remaining: " + formatTime(seconds);

countdown = setInterval(() => {
seconds--;
document.getElementById("timeRemaining").textContent =
"Time Remaining: " + formatTime(seconds);

if (seconds <= 0) {
clearInterval(countdown);
playAlarm();
}
}, 1000);
}

function setup() {
document.getElementById("set").addEventListener("click", () => {
Expand All @@ -19,6 +41,7 @@ function playAlarm() {
}

function pauseAlarm() {
clearInterval(countdown);
audio.pause();
}

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