Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
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
41 changes: 40 additions & 1 deletion Sprint-3/alarmclock/alarmclock.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,42 @@
function setAlarm() {}
const timeRemaining = document.getElementById("timeRemaining");
let timer;
let seconds;

function setAlarm() {
const alarmSetInput = document.getElementById("alarmSet");
seconds = Number(alarmSetInput.value);


if (seconds <= 0 || isNaN(seconds)) {
alert("Please enter a valid number.");
return;
}
Comment on lines +10 to +13

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What type of number should seconds be?


// Stop a previous countdown if there is one
clearInterval(timer);

// Run immediately
decrementTimer();

// decrement each second
timer = setInterval(() => decrementTimer(), 1000);
}

function decrementTimer()
{
const minutes = Math.floor(seconds / 60);
const secs = seconds % 60;

timeRemaining.textContent = `Time Remaining: ${String(minutes).padStart(2, "0")}:${String(secs).padStart(2, "0")}`;

if (seconds <= 0) {
clearInterval(timer);
playAlarm();
return;
}

seconds--;
}

// DO NOT EDIT BELOW HERE

Expand All @@ -23,3 +61,4 @@ function pauseAlarm() {
}

window.onload = setup;

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
Loading