Hey guys, having a bit of an issue changing between colors, I have got it so it just changes one color (in this case, just red) every 1 second to black to indicate a randomly generated color, but would like to change and select all colors (red, green, blue and green) to change to black for one second when prompted. Can anyone give any suggestions on how I may go about this?
const startGame = _ => {
const { colors, startingIndex } = state
state.randomColor = getRandomColors(colors, startingIndex) //Get random colors based on value of startingIndex
let color= document.querySelector('.red')
let originalColor = getComputedStyle(color).backgroundColor //store original color
function changeColor() {
color.style.backgroundColor = 'black'
setTimeout(() => {
color.style.backgroundColor = originalColor
}, 1000)
}
console.log(state.randomColor)
let i = -1
let startInterval = setInterval(() => {
i = (i+1) % state.randomColor.length
if(state.randomColor[i] === 'red') {
changeColor()
}
if(i === state.randomColor.length -1) {
clearInterval(startInterval)
}
}, 1500)
}