Chore Door - play again doesn't reset properly

project url: https://www.codecademy.com/courses/build-interactive-websites/projects/chore-door

The code doesn’t seem to be resetting properly after the first replay.

Any help out there would be very much appreciated.

My code is:

let doorImage1 = document.getElementById('door1');
let doorImage2 = document.getElementById('door2');
let doorImage3 = document.getElementById('door3');

let numClosedDoors = 3;
let openDoor1;
let openDoor2;
let openDoor3;

let botDoorPath = "https://s3.amazonaws.com/codecademy-content/projects/chore-door/images/robot.svg";
let beachDoorPath = "https://s3.amazonaws.com/codecademy-content/projects/chore-door/images/beach.svg";
let spaceDoorPath = "https://s3.amazonaws.com/codecademy-content/projects/chore-door/images/space.svg";
let closedDoorPath = 'https://s3.amazonaws.com/codecademy-content/projects/chore-door/images/closed_door.svg';

let startButton = document.getElementById('start');

let currentlyPlaying = true;

//end global variables

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

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


let playDoor = function (door) {
  numClosedDoors -=1;
  if (numClosedDoors === 0) {
    gameOver('win');
  } else if (isBot(door)){
    gameOver('lose');
  }
}


let randomChoreDoorGenerator = function () {
  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 {
    openDoor3 = botDoorPath;
    openDoor1 = beachDoorPath;
    openDoor2 = spaceDoorPath;    
  }
  
}


doorImage1.onclick =  function () {
	if (currentlyPlaying && !isClicked(doorImage1)) {
      doorImage1.src = openDoor1;
  		playDoor(doorImage1);
  }

};



doorImage2.onclick =  function () {
	if (currentlyPlaying && !isClicked(doorImage2)) {
  	doorImage2.src = openDoor2;
  	playDoor(doorImage2);    
  }

};

doorImage3.onclick =  function () {
  if (currentlyPlaying && !isClicked(doorImage3)) {
  	doorImage3.src = openDoor3;
  	playDoor(doorImage3);    
  }

};

startButton.onclick = function () {
  if (currentlyPlaying === false){
      startRound();
  }

}

let startRound = function () {
  doorImage1.src = closedDoorPath;
  doorImage2.src = closedDoorPath;
  doorImage3.src = closedDoorPath;
  numbClosedDoors = 3;
  startButton.innerHTML = 'Good luck!';
  currentlyPlaying = true;
  randomChoreDoorGenerator();
}



let gameOver = function (status) {
  if (status === 'win'){
    startButton.innerHTML = 'You win! Play again?'
  } else {
    startButton.innerHTML = 'Game over! Play again?'
  }
  currentlyPlaying = false;
}



startRound();


Double check the spelling of your variables in this code block :wink:
Happy Coding!

1 Like

Thank you so much!!!

1 Like