Skip to content

Commit ed3d3cc

Browse files
committed
update html title, convert input value to time format and set dynamic alarm counter
1 parent 96d077b commit ed3d3cc

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

Sprint-3/alarmclock/alarmclock.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,32 @@
1-
function setAlarm() {}
1+
function time_convert(num) {
2+
let minutes = Math.floor((num % 3600) / 60);
3+
let seconds = num % 60;
4+
return minutes.toString().padStart(2, '0') + ":" + seconds.toString().padStart(2, '0');
5+
}
6+
function setAlarm() {
7+
const alarmSetInput = document.getElementById("alarmSet");
8+
const timer = time_convert(alarmSetInput.value)
9+
const timeRemainingCounter = document.getElementById("timeRemaining");
10+
timeRemainingCounter.textContent = `Time Remaining: ${timer}`;
11+
}
12+
13+
// ## How the clock should work
14+
15+
// 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`.
16+
17+
// Every one second the title should count down by one.
18+
19+
// When the `Time Remaining` reaches `00:00` the alarm should play a sound. You can make the sound happen by using `playAlarm()`.
20+
21+
// You can stop the alarm sound by pressing the `Stop Alarm` button.
22+
23+
// ## Need Help?
24+
25+
// Only read this section if you really need to! It's good to work this out for yourself.
26+
27+
// ### Hints
28+
29+
// - Have you tried looking at the `setInterval` function?
230

331
// DO NOT EDIT BELOW HERE
432

Sprint-3/alarmclock/index.html

Lines changed: 3 additions & 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">
@@ -18,3 +18,5 @@ <h1 id="timeRemaining">Time Remaining: 00:00</h1>
1818
<script src="alarmclock.js"></script>
1919
</body>
2020
</html>
21+
22+

0 commit comments

Comments
 (0)