Javascript: How to reset page to initial state with a reset button

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);
}

The problem is that you’ve stored the reference to your resetButton inside the start function, so the reset function has no idea what resetButton is. Just move those variables that need to be accessed by more than one function outside of the function.

BTW when you fix that, you’ll run into a similar issue with other variables - the reset function now complains that it doesn’t know the value of carBlueTime (again, because carBlueTime was only declared inside the start function).

I don’t know if you use the console in codepen, it’ll help you with debugging (button in the lower left).