I'm creating a program where I basically have this button that I made in CSS, and I want him to (when clicked) flash a color, and then 200ms later, return the color to normal, and for some reason I can't get it to work right
function highlight_button(button_id){
button_id.style.backgroundColor="yellow"
sleep(200)
button_id.style.backgroundColor="red"
}
function sleep(milliseconds) {
const date = Date.now();
let currentDate = null;
do {
currentDate = Date.now();
}
while (currentDate - date < milliseconds);
}
highlight_button(myButton);
<button id="myButton">Press</button>
what I thought would happen was the following: -the button would appear yellow immediately -the program would wait 0.2 seconds -the button would appear red
however... the following happens: -the program would wait 0.2 seconds -the button would appear red