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
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<!DOCTYPE html>
<!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>
<title>Martins clock</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" />
<input id="alarmSet" type="number" onfocus="" />

<button id="set" type="button">Set Alarm</button>
<button id="stop" type="button">Stop Alarm</button>
Expand Down
45 changes: 44 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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Currently, the program gets stuck in the last second, and the end button is disabled.

Image

Original file line number Diff line number Diff line change
@@ -1,4 +1,47 @@
function setAlarm() {}
const startButton = document.getElementById("set");
const pause = document.getElementById("stop");
pause.hidden = true;
//begins the count down

// 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;
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)}`;
}
startButton.hidden = true;
pause.hidden = false;
timeInSeconds--;
if (timeInSeconds <= 0) {
clearInterval(clock);
playAlarm();
}

timeRemaining.innerHTML =
"time remaining " + formatTimeDisplay(timeInSeconds);
}, 1000);

pause.addEventListener("click", pauseWhenRunning);
function pauseWhenRunning() {
startButton.hidden = false;
pause.hidden = true;
clearInterval(clock);
document.getElementById("alarmSet").value = timeInSeconds;
audio.pause();
}
}

// 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