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
43 changes: 42 additions & 1 deletion Sprint-3/alarmclock/alarmclock.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,45 @@
function setAlarm() {}
const alarmInput = document.getElementById("alarmSet");
const timeRemaining = document.getElementById("timeRemaining");
const setButton = document.getElementById("set");
const stopButton = document.getElementById("stop");

let counter;

setButton.addEventListener("click", setAlarm);
stopButton.addEventListener("click", pauseAlarm);

function setText() {
const alarmValue = parseInt(alarmInput.value) || 0;

const minutes = Math.floor(alarmValue / 60);
const seconds = alarmValue % 60;

const displayM = String(minutes).padStart(2, "0");
const displayS = String(seconds).padStart(2, "0");

timeRemaining.textContent = `Time Remaining: ${displayM}:${displayS}`;
}

function countdown() {
let alarmValue = parseInt(alarmInput.value) || 0;

if (alarmValue <= 0) {
playAlarm();
clearInterval(counter);
return;
}

alarmInput.value = alarmValue - 1;
setText();
}

function setAlarm() {
clearInterval(counter);

setText();

counter = setInterval(countdown, 1000);
}

// DO NOT EDIT BELOW HERE

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