Skip to content

Commit 9676d86

Browse files
committed
created alarm clock function based on required requirements and test requirements.
1 parent d746294 commit 9676d86

File tree

3 files changed

+7234
-2
lines changed

3 files changed

+7234
-2
lines changed

Sprint-3/alarmclock/alarmclock.js

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,46 @@
1-
function setAlarm() {}
1+
let countDown;
2+
let remainingSeconds = 0;
3+
4+
function setAlarm() {
5+
let timeRemaining = document.getElementById("timeRemaining");
6+
let alarmSet = document.getElementById("alarmSet").value;
7+
remainingSeconds = Number(alarmSet);
8+
if (isNaN(remainingSeconds) || remainingSeconds <= 0) {
9+
prompt("please enter a value greater than zero!");
10+
return;
11+
}
12+
displayTime();
13+
countDown = setInterval(timer, 1000);
14+
}
15+
16+
function displayTime() {
17+
let timeRemaining = document.getElementById("timeRemaining");
18+
let hour = Math.floor(remainingSeconds / 3600);
19+
let minutes = Math.floor((remainingSeconds % 3600) / 60);
20+
let seconds = Math.floor(remainingSeconds % 60);
21+
22+
if (minutes < 10) {
23+
minutes = "0" + minutes;
24+
}
25+
if (seconds < 10) {
26+
seconds = "0" + seconds;
27+
}
28+
29+
if (hour > 0) {
30+
timeRemaining.textContent = `Time Remaining: ${hour}:${minutes}:${seconds}`;
31+
} else {
32+
timeRemaining.textContent = `Time Remaining: ${minutes}:${seconds}`;
33+
}
34+
}
35+
36+
function timer() {
37+
remainingSeconds--;
38+
displayTime();
39+
if (remainingSeconds <= 0) {
40+
clearInterval(countDown);
41+
playAlarm();
42+
}
43+
}
244

345
// DO NOT EDIT BELOW HERE
446

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

0 commit comments

Comments
 (0)