Skip to content
Open
Show file tree
Hide file tree
Changes from 5 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
47 changes: 46 additions & 1 deletion Sprint-3/alarmclock/alarmclock.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,49 @@
function setAlarm() {}
let timer;

function setAlarm() {
const timeSet = document.getElementById("alarmSet").value;
const time = countdown(timeSet);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What's the point of this time variable now?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

have removed variable assignment as after deleting code snippet before, it is no longer used. countdown(timeSet) is run without result assigned to variable.

}

function countdown(time) {
clearInterval(timer);
let timeRemaining = time;
if (timeRemaining > 5999) {
timeRemaining = 5999;
}
updateShownTime(timeRemaining);

timer = setInterval(() => {
timeRemaining -= 1;
if (timeRemaining == 0) {
clearInterval(timer);
playAlarm();
}
updateShownTime(timeRemaining);
}, 1000);
}

function updateShownTime(timeRemaining) {
let timeRemainingOutput = document.getElementById("timeRemaining");
let title = document.getElementById("title");
const formattedTime = convertTime(timeRemaining);
const printedTime = printTime(formattedTime);
timeRemainingOutput.textContent = `Time Remaining: ${printedTime}`;
title.textContent = `Time Remaining: ${printedTime}`;
}

function convertTime(timeSeconds) {
const seconds = timeSeconds % 60;
const minutes = (timeSeconds - seconds) / 60;
console.log([minutes, seconds]);
return [minutes, seconds];
}

function printTime(time) {
const paddedHours = String(time[0]).padStart(2, "0");
const paddedSeconds = String(time[1]).padStart(2, "0");
return paddedHours + ":" + paddedSeconds;
}

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