Skip to content

Commit 0dfe10c

Browse files
Alex JamshidiAlex Jamshidi
authored andcommitted
code complete, all tests passed
1 parent 2fa60e6 commit 0dfe10c

2 files changed

Lines changed: 25 additions & 21 deletions

File tree

Sprint-3/alarmclock/alarmclock.js

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,36 @@
1+
let timer;
2+
13
function setAlarm() {
2-
timeRemaining = document.getElementById("timeRemaining")
34
timeSet = document.getElementById("alarmSet").value
4-
const time = convertTime(timeSet)
5-
6-
7-
8-
9-
timeRemaining.textContent = `Time Remaining: ${remainingMinutes}:${remainingSeconds}`
5+
const time = countdown(timeSet)
6+
if (time > 0) {
7+
countdown(time);
8+
}
109
}
1110

1211
function countdown(time) {
13-
setInterval(() => {
14-
12+
clearInterval(timer);
13+
let timeRemaining = time;
14+
if (timeRemaining > 5999) {timeRemaining = 5999};
15+
UpdateShownTime(timeRemaining)
16+
17+
timer = setInterval(() => {
18+
timeRemaining -= 1;
19+
if (timeRemaining == 0 ) {clearInterval(timer); playAlarm();}
20+
UpdateShownTime(timeRemaining)
1521
}, 1000)
1622
}
1723

24+
function UpdateShownTime(timeRemaining) {
25+
let timeRemainingOutput = document.getElementById("timeRemaining");
26+
let title = document.getElementById("title");
27+
const formattedTime = convertTime(timeRemaining);
28+
const printedTime = printTime(formattedTime);
29+
timeRemainingOutput.textContent = `Time Remaining: ${printedTime}`;
30+
title.textContent = `Time Remaining: ${printedTime}`;
31+
}
32+
1833
function convertTime(timeSeconds) {
19-
if (timeSeconds > 5999) {return [99, 59]};
2034
const seconds = timeSeconds % 60;
2135
const minutes = (timeSeconds - seconds) / 60;
2236
console.log([minutes, seconds])
@@ -29,16 +43,7 @@ function printTime(time) {
2943
return paddedHours + ":" + paddedSeconds;
3044
}
3145

32-
printTime([50,40])
33-
printTime([50,4])
34-
printTime([5,40])
35-
36-
convertTime(5000000)
37-
convertTime(50)
38-
convertTime(500)
39-
convertTime(5000000)
4046

41-
/*
4247
// DO NOT EDIT BELOW HERE
4348

4449
var audio = new Audio("alarmsound.mp3");
@@ -62,4 +67,3 @@ function pauseAlarm() {
6267
}
6368

6469
window.onload = setup;
65-
*/

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 id="title">Alarm Clock app</title>
88
</head>
99
<body>
1010
<div class="centre">

0 commit comments

Comments
 (0)