Chore door Step 70 - Unresponsive ReStart Button


#1

project url: https://www.codecademy.com/paths/web-development/tracks/building-interactive-javascript-websites/modules/web-dev-interactive-websites/projects/chore-door

My chore door code works just fine until I attempt to restart the game with the start button. It feels like a case of so near and yet so far! The game has played through and the button displays either “Game Over! Play again?” or “You Win! Play Again?” but then the onclick code does not seem to work for the button. I have to refresh the page to start again…
Any help out there would be very much appreciated…

My code is:

document.getElementById('door1');
let doorImage2 =
document.getElementById('door2');
let doorImage3 =
document.getElementById('door3');
let startButton =
document.getElementById('start');
let numClosedDoors = 3;
let openDoor1;
let openDoor2;
let openDoor3;
let currentlyPlaying = true;
const botDoorPath = 'https://s3.amazonaws.com/codecademy-content/projects/chore-door/images/robot.svg';
const beachDoorPath = 'https://s3.amazonaws.com/codecademy-content/projects/chore-door/images/beach.svg';
const spaceDoorPath = 'https://s3.amazonaws.com/codecademy-content/projects/chore-door/images/space.svg';
const closedDoorPath = 'https://s3.amazonaws.com/codecademy-content/projects/chore-door/images/closed_door.svg';


const isBot = (door) =>{
 if(door.src === botDoorPath){
    return true;
  } else {
    return false;}
}

const isClicked = (door) => {
  if(door.src === closedDoorPath){
    return false;
  } else {
    return true;}
  }

const playDoor = (door) => {
numClosedDoors--;
  if(numClosedDoors === 0){
    gameOver('win');}
  //59 below
  else if(isBot(door)){
    gameOver();
    }
  }

let randomChoreDoorGenerator = () => {
  let choreDoor = Math.floor(Math.random() * numClosedDoors);

  if(choreDoor === 0){
  openDoor1 = botDoorPath;
  openDoor2 = beachDoorPath;
  openDoor3 = spaceDoorPath;
  }
  else if (choreDoor === 1){
  openDoor2 = botDoorPath;
  openDoor3 = beachDoorPath;
  openDoor1= spaceDoorPath;
  }
  else if (choreDoor === 2){
  openDoor3 = botDoorPath;
  openDoor1 = beachDoorPath;
  openDoor2 = spaceDoorPath;
   }
  }
door1.onclick = () =>{
 if(!isClicked(doorImage1) && currentlyPlaying){
  doorImage1.src = openDoor1;
  playDoor(door1);}
}
door2.onclick = () =>{
if(!isClicked(doorImage2) && currentlyPlaying){
  doorImage2.src = openDoor2;
  playDoor(door2);}
}
door3.onclick = () =>{
if(!isClicked(doorImage3) && currentlyPlaying){
  doorImage3.src = openDoor3;
  playDoor(door3);}
}

const startRound = () =>{
     doorImage1.src = closedDoorPath;
     doorImage2.src = closedDoorPath;
     doorImage3.src = closedDoorPath;
     numClosedDoors = 3;
     startButton.innerHTML = 'Good Luck';
     currentlyPlaying = true;
     randomChoreDoorGenerator();
  }

startButton.onClick = () => {
if(!currentlyPlaying){
startRound();
}
}


const gameOver = (str) =>{
     if(str === 'win'){
    startButton.innerHTML = 'You win! Play again?';
  } else {
   startButton.innerHTML = 'Game Over! Play again?';
 };
currentlyPlaying = false;
};
startRound();```

#2

onClick is not the same as onclick, which why your code isn’t working.


#3

I can’t believe I missed that! Thank you so much stetim94!!, all working well now!