Skip to content

Commit fd7a1c6

Browse files
committed
happy with my clock
1 parent f8431ee commit fd7a1c6

File tree

4 files changed

+66
-15
lines changed

4 files changed

+66
-15
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<link rel="stylesheet" href="style.css" />
7+
<title>Title here</title>
8+
</head>
9+
<body>
10+
<div class="centre">
11+
<h1 id="timeRemaining">Time Remaining: 00:00</h1>
12+
<label for="alarmSet">Set time to:</label>
13+
<input id="alarmSet" type="number" onfocus="" />
14+
15+
<button id="set" type="button">Set Alarm</button>
16+
<button id="stop" type="button">Stop Alarm</button>
17+
</div>
18+
<script src="alarmclock.js"></script>
19+
</body>
20+
</html>

Sprint-3/alarmclock/alarmclock.js

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,36 @@
1-
let timeIn = document.getElementById("alarmSet").value;
2-
let countDown = document.getElementById("timeRemaining");
1+
botton = document.getElementById("set");
2+
//begins the count down
3+
botton.addEventListener("click", setAlarm);
34

5+
// document.getElementById("set").addEventListener("click", setAlarm);
6+
const timeRemaining = document.getElementById("timeRemaining");
47
function setAlarm() {
5-
timeIn--;
6-
countDown.innerHTML = "timeRemaining " + ":" + timeIn;
7-
if (timeIn < 1) {
8-
playAlarm;
9-
clearInterval(timer);
10-
}
8+
// gets the value of the input field and stores it in a variable
9+
let timeInSeconds = document.getElementById("alarmSet").value;
10+
11+
let clock = setInterval(() => {
12+
function pad(num) {
13+
return num.toString().padStart(2, "0");
14+
}
15+
16+
function formatTimeDisplay(timeInSeconds) {
17+
const remainingSeconds = timeInSeconds % 60;
18+
const totalMinutes = (timeInSeconds - remainingSeconds) / 60;
19+
const remainingMinutes = totalMinutes % 60;
20+
const totalHours = (totalMinutes - remainingMinutes) / 60;
21+
22+
return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`;
23+
}
24+
25+
timeInSecond = timeInSeconds--;
26+
if (timeInSeconds == 0) {
27+
clearInterval(clock);
28+
playAlarm();
29+
}
30+
timeRemaining.innerHTML =
31+
"time remaining " + formatTimeDisplay(timeInSeconds);
32+
}, 1000);
1133
}
12-
const timer = setInterval(setAlarm, 1000);
13-
14-
// setTimeout(count, 1000);
1534

1635
// DO NOT EDIT BELOW HERE
1736

Sprint-3/alarmclock/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,8 @@
1313
"bugs": {
1414
"url": "https://github.com/CodeYourFuture/CYF-Coursework-Template/issues"
1515
},
16-
"homepage": "https://github.com/CodeYourFuture/CYF-Coursework-Template#readme"
16+
"homepage": "https://github.com/CodeYourFuture/CYF-Coursework-Template#readme",
17+
"dependencies": {
18+
"jest": "^30.3.0"
19+
}
1720
}

Sprint-3/alarmclock/style.css

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
1+
body {
2+
min-width: fit-content;
3+
font-size: 20px;
4+
background-color: darkorchid;
5+
color: rgb(113, 48, 48);
6+
}
7+
18
.centre {
29
position: fixed;
310
top: 50%;
411
left: 50%;
512
-webkit-transform: translate(-50%, -50%);
613
transform: translate(-50%, -50%);
714
}
8-
15+
button {
16+
border-radius: 30px;
17+
}
918
#alarmSet {
10-
margin: 20px;
19+
margin: 0px;
1120
}
1221

1322
h1 {
14-
text-align: center;
23+
text-align: right;
1524
}

0 commit comments

Comments
 (0)