I am replicating a simon game prototype and I am trying to write a function for a button blink in vanilla js.
Currently I have the following function:
function blinkColor(color) {
let colorButton = document.getElementById(color);
colorButton.style.background = *highlightColor*;
setTimeout(() => {colorButton.style.background = *originalColor*}, 1000);
}
I am replacing the buttons color with another brighter color and then changing it back again with a timeout. It works when the consecutive colors are different from each other but when it needs to blink the same color more then once (e.g 'red', 'red', 'red'), it does not leave a break in between the blinks and it looks like it is just making one long blink.
Is there a better way to write this functionality?