Skip to content

GLASGOW | May-2025 | Taras Mykytiuk | Module-Data-Groups | Sprint_3 | Alarm_Clock #614

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 1 commit 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
25 changes: 24 additions & 1 deletion Sprint-3/alarmclock/alarmclock.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,27 @@
function setAlarm() {}
function setAlarm() {
let timerDom = document.getElementById("timeRemaining");
let timeInputValue = document.getElementById("alarmSet").value;
setTimer(timerDom, formatTime(timeInputValue));
let interval = setInterval(function () {
timeInputValue--;
setTimer(timerDom, formatTime(timeInputValue));
if (timeInputValue == 0) {
playAlarm();
clearInterval(interval);
}
}, 1000);
}

function formatTime(seconds) {
let minutes = Math.trunc(seconds / 60);
let remainingSeconds = seconds % 60;
let formattedTime = minutes.toString().padStart(2, '0') + ':' + remainingSeconds.toString().padStart(2, '0');
return formattedTime;
}

function setTimer(timerDon, timeInputValue) {
timerDon.textContent = "Time Remaining: " + String(timeInputValue);
}

// DO NOT EDIT BELOW HERE

Expand Down
37 changes: 20 additions & 17 deletions Sprint-3/alarmclock/index.html
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
<!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>
</head>
<body>
<div class="centre">
<h1 id="timeRemaining">Time Remaining: 00:00</h1>
<label for="alarmSet">Set time to:</label>
<input id="alarmSet" type="number" />

<button id="set" type="button">Set Alarm</button>
<button id="stop" type="button">Stop Alarm</button>
</div>
<script src="alarmclock.js"></script>
</body>
</html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="style.css" />
<title>Alarm clock app</title>
</head>

<body>
<div class="centre">
<h1 id="timeRemaining">Time Remaining: 00:00</h1>
<label for="alarmSet">Set time to:</label>
<input id="alarmSet" type="number" />

<button id="set" type="button">Set Alarm</button>
<button id="stop" type="button">Stop Alarm</button>
</div>
<script src="alarmclock.js"></script>
</body>

</html>