Skip to content

Commit f5da05e

Browse files
committed
code implemented
1 parent 96d077b commit f5da05e

3 files changed

Lines changed: 29 additions & 3 deletions

File tree

Sprint-3/alarmclock/alarmclock.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,25 @@
1-
function setAlarm() {}
1+
function setAlarm() {
2+
const input = document.getElementById('alarmSet');
3+
const heading = document.getElementById('timeRemaining');
4+
let totalSeconds = parseInt(input.value) || 0;
5+
6+
function updateDisplay() {
7+
const minutes = Math.floor(totalSeconds / 60);
8+
const seconds = totalSeconds % 60;
9+
heading.innerText = `Time Remaining: ${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
10+
11+
if (totalSeconds > 0) {
12+
totalSeconds--;
13+
} else {
14+
playAlarm();
15+
clearInterval(intervalId); // Stop interval after alarm
16+
}
17+
}
18+
19+
updateDisplay(); // Set initial time
20+
const intervalId = setInterval(updateDisplay, 1000);
21+
}
22+
223

324
// DO NOT EDIT BELOW HERE
425

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: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,10 @@
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+
"@jest/globals": "^30.3.0",
19+
"jest": "^30.3.0",
20+
"jsdom": "^26.1.0"
21+
}
1722
}

0 commit comments

Comments
 (0)