-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay24_ChristmasTreeLights.js
175 lines (153 loc) Β· 3.58 KB
/
Day24_ChristmasTreeLights.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<!-- <!doctype html>
<html>
<head>
<title>Christmas Tree Lights Sequencer</title>
<link rel="stylesheet" href="index.css">
</head>
<body>
<section>
<img src="/tree1.png" alt="christmas tree">
<div class="star">βοΈ</div>
<div class="lights red"></div>
<div class="lights blue"></div>
<div class="lights blue"></div>
<div class="lights red"></div>
<div class="lights red"></div>
<div class="lights blue"></div>
<div class="lights blue"></div>
<div class="lights red"></div>
<div class="lights red"></div>
<div class="lights blue"></div>
<div class="lights red"></div>
<div class="lights blue"></div>
</section>
<script src="index.js"></script>
</body>
</html>
html, body {
margin: 0;
padding: 0;
}
body {
background-color: #abb997;
display: flex;
align-items: center;
height: 100vh;
}
section {
max-width: 250px;
margin: 0 auto;
position: relative;
}
img {
max-width: 100%;
}
.star{
top: 60px;
left: 108px;
font-size: 2em;
position: absolute;
}
.lights {
width: 17px;
height: 17px;
position: absolute;
border-radius: 50%;
}
.lights:nth-child(3) {
top: 118px;
left: 95px;
}
.lights:nth-child(4) {
top: 118px;
left: 135px;
}
.lights:nth-child(5) {
top: 172px;
left: 70px;
}
.lights:nth-child(6) {
top: 180px;
left: 165px;
}
.lights:nth-child(7) {
top: 230px;
left: 50px;
}
.lights:nth-child(8) {
top: 223px;
left: 175px;
}
.lights:nth-child(9) {
top: 280px;
left: 40px;
}
.lights:nth-child(10) {
top: 280px;
left: 190px;
}
.lights:nth-child(11) {
top: 150px;
left: 120px;
}
.lights:nth-child(12) {
top: 200px;
left: 120px;
}
.lights:nth-child(13) {
top: 250px;
left: 120px;
}
.lights:nth-child(14) {
top: 290px;
left: 120px;
}
.red {
background: radial-gradient(circle at 65% 15%, white 1px, #FF3131 30%, darkred 60%, aqua 100%);
filter: brightness(.8);
}
.blue {
background: radial-gradient(circle at 65% 15%, white 1px, aqua 30%, darkblue 60%, aqua 100%);
filter: brightness(.8);
}
.lights-on {
filter: unset;
}
-->
// /**
// * π Challenge:
// * 1. The Christmas tree's lights should switch
// * on and off every 800 miliseconds.
// *
// * Stretch Goal:
// * Make the blue and red lights flash alternately.
// **/
function switchLights() {
setInterval(function() {
let redLights = document.getElementsByClassName("red")
let blueLights = document.getElementsByClassName("blue")
// turn on red lights
for (let i = 0; i < redLights.length; i++) {
redLights[i].style.filter = "none"
}
// turn off red lights after 1.5 seconds
setTimeout(function() {
for (let i = 0; i < redLights.length; i++) {
redLights[i].style.filter = "grayscale(100%)"
}
}, 1500)
// turn on blue lights after 1.5 seconds
setTimeout(function() {
for (let i = 0; i < blueLights.length; i++) {
blueLights[i].style.filter = "none"
}
}, 1500)
// turn off blue lights after 1.5 seconds
setTimeout(function() {
for (let i = 0; i < blueLights.length; i++) {
blueLights[i].style.filter = "grayscale(100%)"
}
}, 3000)
}, 3000) // total interval for switching lights
}
switchLights()