Skip to content

London | 25-ITP-May | Hakan Murat Kavut | Sprint 3 - Alarm Clock #653

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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: 28 additions & 1 deletion Sprint-3/alarmclock/alarmclock.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,31 @@
function setAlarm() {}
let countdownInterval;

function setAlarm() {
const inputArea = document.getElementById("alarmSet");
let remaining = Number(inputArea.value);

if (isNaN(remaining) || remaining <= 0) return;

updateDisplay(remaining); // update first time immediately

countdownInterval = setInterval(() => {
remaining--;
updateDisplay(remaining);

if (remaining <= 0) {
clearInterval(countdownInterval);
playAlarm();
}
}, 1000);
}

function updateDisplay(seconds) {
const countDown = document.getElementById("timeRemaining");
const minutes = String(Math.floor(seconds / 60)).padStart(2, "0");
const secs = String(seconds % 60).padStart(2, "0");
countDown.innerText = `Time Remaining: ${minutes}:${secs}`;
}


// DO NOT EDIT BELOW HERE

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 app</title>
</head>
<body>
<div class="centre">
Expand Down