Could someone help me with getting a reset button working? I have a simple racing game I created and when I hit the reset button I get my cars back to the position I need and such. But I also need help getting things back to the original state that way I can it can be played again. My codepen is here https://codepen.io/fkhan698/pen/oNLJqMJ. This is the code I have
redRaceButton.addEventListener('click', start);
resetButton.addEventListener('click', reset);
function start (){
let timer;
redRaceButton.style.display = "none";
greenRaceButton.style.display = "block";
resetButton.style.display = "block";
console.log("Reset button was clicked")
timer = setTimeout( () => {
carBlue.classList.add('moveRight');
}, carBlueTime,9000);
timer = setTimeout( () => {
carRed.classList.add('moveRight');
}, carRedTime, 9000);
if(carBlueTime < carRedTime){
console.log("Red won");
output.innerText = "Blue won!";
} else if(carBlueTime > carRedTime ){
output.innerText = "Red won!";
} else {
output.innerText = "Draw!"
}
}
function reset(){
redRaceButton.style.display = "block";
greenRaceButton.style.display = "none";
output.innerText = "";
resetButton.style.display = "";
timer = setTimeout( () => {
carBlue.classList.add('moveLeft');
}, carBlueTime,9000);
timer = setTimeout( () => {
carRed.classList.add('moveLeft');
}, carRedTime, 9000);
}