Skip to content

Commit 188f02b

Browse files
copmleted alarm clock app
1 parent 96d077b commit 188f02b

3 files changed

Lines changed: 47 additions & 3 deletions

File tree

Sprint-3/alarmclock/alarmclock.js

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,42 @@
1-
function setAlarm() {}
1+
const timeRemaining = document.querySelector("#timeRemaining");
2+
3+
let intervalId;
4+
5+
6+
7+
function setAlarm() {
8+
// I will use the function showTime twice, one for showing the time just after the user clicks the set button and another one for updating the time every second in countdown function
9+
function showTime() {
10+
// getting te mins and seconds from the inputValue in appropriate format
11+
const minutes = Math.floor(inputValue / 60)
12+
.toString()
13+
.padStart(2, "0");
14+
const seconds = (inputValue % 60).toString().padStart(2, "0");
15+
//Gathering everything together and outputing remaining time
16+
timeRemaining.innerText = `Time Remaining: ${minutes}:${seconds}`;
17+
};
18+
// I added the next line in case if we want to reset the time for alarm
19+
clearInterval(intervalId);
20+
// getting the input value in number format
21+
let inputValue = Number(document.querySelector("#alarmSet").value);
22+
showTime();
23+
intervalId = setInterval(countdown, 1000);
24+
25+
function countdown() {
26+
if (inputValue > 0) {
27+
//decrease the entered number by 1
28+
inputValue--;
29+
showTime();
30+
}
31+
// When the inputValue is 0, play the alarm and clear interval so that the function stops initialising
32+
else {
33+
playAlarm();
34+
clearInterval(intervalId);
35+
}
36+
}
37+
}
38+
39+
240

341
// DO NOT EDIT BELOW HERE
442

@@ -20,6 +58,8 @@ function playAlarm() {
2058

2159
function pauseAlarm() {
2260
audio.pause();
61+
//I know it's said to not edit this code, I wonder if it's ok to add this line below in order to pause the time before the time runs out.
62+
clearInterval(intervalId);
2363
}
2464

2565
window.onload = setup;

Sprint-3/alarmclock/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<meta charset="utf-8" />
55
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
66
<link rel="stylesheet" href="style.css" />
7-
<title>Title here</title>
7+
<title>Alarm clock app</title>
88
</head>
99
<body>
1010
<div class="centre">

Sprint-3/alarmclock/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,9 @@
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+
"devDependencies": {
18+
"@testing-library/jest-dom": "^6.9.1",
19+
"jest-environment-jsdom": "^30.3.0"
20+
}
1721
}

0 commit comments

Comments
 (0)