* 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()
/**
* 🎄 Challenge: