Skip to content

Commit 121305d

Browse files
committed
Completed alarm clock
1 parent 2c5d12f commit 121305d

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

Sprint-3/alarmclock/alarmclock.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,28 @@
1-
function setAlarm() {}
21

2+
let myTimer;
3+
function setAlarm() {
4+
// fist need to get the input from the id=alarmset
5+
let setTimeSeconds = document.getElementById("alarmSet").value;
6+
console.log(setTimeSeconds);
7+
myTimer = setInterval(() => {
8+
const minutes = Math.trunc(setTimeSeconds / 60);
9+
const seconds = setTimeSeconds % 60;
10+
console.log(minutes);
11+
// then update time remaining whith the value of alarm set
12+
const upDate = document.getElementById("timeRemaining");
13+
// Time Remaining: 00:00
14+
upDate.innerHTML = `Time Remaining: ${minutes
15+
.toString()
16+
.padStart(2, "0")}: ${seconds.toString().padStart(2, "0")}`;
17+
// Check if we get to zero
18+
if (setTimeSeconds <= 0) {
19+
playAlarm();
20+
clearInterval(myTimer);
21+
}
22+
// need tomake the functon counting donw seconds by one until get 00:00
23+
setTimeSeconds = setTimeSeconds - 1;
24+
}, 1000);
25+
}
326
// DO NOT EDIT BELOW HERE
427

528
var audio = new Audio("alarmsound.mp3");

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)