Skip to content

Commit 9ddf206

Browse files
committed
add color changing background and update card style
1 parent 473b4a4 commit 9ddf206

File tree

2 files changed

+54
-9
lines changed

2 files changed

+54
-9
lines changed

Sprint-3/alarmclock/alarmclock.js

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
let alarmInterval;
2+
let colorInterval;
23

34
function setAlarm() {
45
clearInterval(alarmInterval);
5-
let timeRemaining = document.getElementById("alarmSet");
6-
const display = document.getElementById("timeRemaining");
6+
const timeRemaining = document.querySelector("#alarmSet");
7+
const display = document.querySelector("#timeRemaining");
8+
if (!timeRemaining || !display) return;
79
//what ever we input is turned into seconds
810
let totalSeconds = parseInt(timeRemaining.value);
911

@@ -30,6 +32,49 @@ function setAlarm() {
3032
}
3133
}, 1000);
3234
}
35+
//add color changing background when alarm reaches 0 until stopped.
36+
//function from color changing assignment 10 year ago!
37+
function makeRandomColor() {
38+
var colorOptions = '0123456789ABCDEF';
39+
var newColor = '#';
40+
//repeat 6 times to generate 6 random hex digits from the 16 characters in colorOptions
41+
for (var i = 0; i < 6; i++) {
42+
//picks random numbers from colorOptions and appends it to the # to make a new color.
43+
newColor += colorOptions[Math.floor(Math.random() * 16)];
44+
}
45+
return newColor;
46+
}
47+
//end color changing
48+
49+
//keep the existing code below and call the setup
50+
//set the background color transition
51+
document.body.style.transition = "background-color 0.7s ease";
52+
// call the entire page
53+
window.addEventListener("load", function () {
54+
// attach the alarm sound to the make Random color so it starts changing when the alarm starts.
55+
audio.addEventListener("play", () => {
56+
// stops any previous color changing intervals
57+
clearInterval(colorInterval);
58+
//starts a new repeating timer and saves it's ID in colorInterval. setInterval runs every 2seconds
59+
colorInterval = setInterval(() => {
60+
//style the background and make it important! so it over-rides the style.css
61+
document.body.style.setProperty(
62+
"background-color",
63+
makeRandomColor(),
64+
"important"
65+
);
66+
//closes setInterval after 2 seconds
67+
}, 1000);
68+
});
69+
70+
audio.addEventListener("pause", () => {
71+
clearInterval(colorInterval);
72+
document.body.style.backgroundColor = "";
73+
});
74+
});
75+
//not sure that this is helping. The function works without it.
76+
window.setAlarm = setAlarm;
77+
//end linking
3378

3479
// DO NOT EDIT BELOW HERE
3580

Sprint-3/alarmclock/style.css

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
}
77

88
body {
9-
background: linear-gradient(#d49562, #9e897c);
10-
color: #797d8131;
9+
background: #c5b7a9;
10+
color: #797d8131;
1111
height: 100vh;
1212
display: flex;
1313
justify-content: center;
@@ -16,7 +16,7 @@ body {
1616

1717
/* Centered card*/
1818
.centre {
19-
background-color: #a16093;
19+
background-color: #000000;
2020
padding: 40px 60px;
2121
border-radius: 10px;
2222
text-align: center;
@@ -62,18 +62,18 @@ button {
6262

6363
/* Set Alarm */
6464
#set {
65-
background-color: #2b2c2d;
65+
background-color: #1f6718;
6666
color: #fff;
6767
}
6868

6969
#set:hover {
70-
background-color: #2b2c2d7b;
71-
transform: translateY(-2px);
70+
background-color: #447f3d;
71+
transform: translateY(-1px);
7272
}
7373

7474
/* Stop Alarm */
7575
#stop {
76-
background-color: #2b2c2d;
76+
background-color: #825047;
7777
color: #fff;
7878
}
7979

0 commit comments

Comments
 (0)