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
File renamed without changes.
20 changes: 20 additions & 0 deletions Sprint-3/alarmclock/alarmClockApp.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!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" onfocus="" />

<button id="set" type="button">Set Alarm</button>
<button id="stop" type="button">Stop Alarm</button>
</div>
<script src="alarmclock.js"></script>
</body>
</html>
36 changes: 35 additions & 1 deletion Sprint-3/alarmclock/alarmclock.js
Copy link
Copy Markdown

@WeiTsungCheng WeiTsungCheng Mar 30, 2026

Choose a reason for hiding this comment

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

basic operate is fine, but second round would remain last round info, causing non-normal appearance

Image Image The screen repeatedly switches between different times.

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.

i have set a lock out after the button is clicked till the alarm goes off

Original file line number Diff line number Diff line change
@@ -1,4 +1,38 @@
function setAlarm() {}
botton = document.getElementById("set");
//begins the count down
botton.addEventListener("click", setAlarm);

// document.getElementById("set").addEventListener("click", setAlarm);
const timeRemaining = document.getElementById("timeRemaining");
function setAlarm() {
// gets the value of the input field and stores it in a variable
let timeInSeconds = document.getElementById("alarmSet").value;
botton.disabled = true;

let clock = setInterval(() => {
function pad(num) {
return num.toString().padStart(2, "0");
}

function formatTimeDisplay(timeInSeconds) {
const remainingSeconds = timeInSeconds % 60;
const totalMinutes = (timeInSeconds - remainingSeconds) / 60;
const remainingMinutes = totalMinutes % 60;
const totalHours = (totalMinutes - remainingMinutes) / 60;

return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`;
}

timeInSecond = timeInSeconds--;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

timeInSecond is not used

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.

with out this the clock wont tick down

if (timeInSeconds == 0) {
clearInterval(clock);
playAlarm();
botton.disabled = false;
}
timeRemaining.innerHTML =
"time remaining " + formatTimeDisplay(timeInSeconds);
}, 1000);
}

// DO NOT EDIT BELOW HERE

Expand Down
5 changes: 4 additions & 1 deletion Sprint-3/alarmclock/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@
"bugs": {
"url": "https://github.com/CodeYourFuture/CYF-Coursework-Template/issues"
},
"homepage": "https://github.com/CodeYourFuture/CYF-Coursework-Template#readme"
"homepage": "https://github.com/CodeYourFuture/CYF-Coursework-Template#readme",
"dependencies": {
"jest": "^30.3.0"
}
}
15 changes: 12 additions & 3 deletions Sprint-3/alarmclock/style.css
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
body {
min-width: fit-content;
font-size: 20px;
background-color: darkorchid;
color: rgb(113, 48, 48);
}

.centre {
position: fixed;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}

button {
border-radius: 30px;
}
#alarmSet {
margin: 20px;
margin: 0px;
}

h1 {
text-align: center;
text-align: right;
}
Loading