Skip to content

Commit e929c4a

Browse files
committed
Sprint-3: implement alarmclock
1 parent de6889c commit e929c4a

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

‎Sprint-3/alarmclock/alarmclock.js‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,24 @@
1-
function setAlarm() {}
1+
function setAlarm() {
2+
let seconds = parseInt(document.getElementById("alarmSet").value, 10);
3+
const heading = document.getElementById("timeRemaining");
4+
5+
function formatTime(s) {
6+
const mins = String(Math.floor(s / 60)).padStart(2, "0");
7+
const secs = String(s % 60).padStart(2, "0");
8+
return `Time Remaining: ${mins}:${secs}`;
9+
}
10+
11+
heading.innerText = formatTime(seconds);
12+
13+
const timer = setInterval(() => {
14+
seconds--;
15+
heading.innerText = formatTime(seconds);
16+
if (seconds <= 0) {
17+
clearInterval(timer);
18+
playAlarm();
19+
}
20+
}, 1000);
21+
}
222

323
// DO NOT EDIT BELOW HERE
424

‎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)