Skip to content

Commit 30f9803

Browse files
alarm clock app done
1 parent 4222cda commit 30f9803

3 files changed

Lines changed: 39 additions & 2 deletions

File tree

‎Sprint-3/alarmclock/alarmclock.js‎

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,33 @@
1-
function setAlarm() {}
1+
// ## How the clock should work
22

3+
// When you click the `Set Alarm` button the counter at the top of the screen should change to the number you entered in the `input` field. For example, if the `input` field says `10` then the title should say `Time Remaining: 00:10`.
4+
5+
// Every one second the title should count down by one.
6+
7+
// When the `Time Remaining` reaches `00:00` the alarm should play a sound. You can make the sound happen by using `playAlarm()`.
8+
9+
// You can stop the alarm sound by pressing the `Stop Alarm` button.
10+
11+
//
12+
const alarmInput = document.querySelector("#alarmSet");
13+
const setButton = document.querySelector("#set");
14+
const timeRemaining = document.querySelector("#timeRemaining");
15+
function setAlarm() {
16+
let totalSeconds = Number(alarmInput.value);
17+
const timer = setInterval(() => {
18+
totalSeconds--;
19+
const minutes = String(Math.floor(totalSeconds / 60)).padStart(2, "0");
20+
const seconds = String(Math.floor(totalSeconds % 60)).padStart(2, "0");
21+
const remainingTime = minutes + ":" + seconds;
22+
timeRemaining.innerText = `Time Remaining:${remainingTime}`;
23+
if (totalSeconds === 0) {
24+
clearInterval(timer);
25+
playAlarm();
26+
}
27+
}, 1000);
28+
}
29+
30+
setButton.addEventListener("click", setAlarm);
331
// DO NOT EDIT BELOW HERE
432

533
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
@@ -1,4 +1,4 @@
1-
<!DOCTYPE html>
1+
<!doctype html>
22
<html lang="en">
33
<head>
44
<meta charset="utf-8" />

‎Sprint-3/alarmclock/style.css‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,13 @@
1212

1313
h1 {
1414
text-align: center;
15+
color: rgb(117, 13, 13);
16+
}
17+
body {
18+
background-color: rgb(197, 107, 122);
19+
}
20+
button {
21+
background-color: rgb(151, 77, 114);
22+
color: white;
23+
padding: 10px;
1524
}

0 commit comments

Comments
 (0)