ChoreBot

Hello, I know that I have not completed the project yet, but for some reason, I am unable to open the doors.

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

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 numClosedDoors = 3
let openDoor1, openDoor2, openDoor3;

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

const playDoor = () =>{
  numClosedDoors--;
  if(numClosedDoors === 0){
    gameOver('win');
  }
}

const randomChoreDoorGenerator = () => {
  const choreDoor = Math.floor(Math.random() * numClosedDoors);
  if(choreDoor === 0){
    openDoor1 = botDoorPath;
    openDoor2 = spaceDoorPath;
    openDoor3 = beachDoorPath;
  }
  else if(choreDoor === 1){
    openDoor2 = botDoorPath;
    openDoor3 = spaceDoorPath;
    openDoor1 = beachDoorPath;
  }
  else{
    openDoor3 = botDoorPath;
    openDoor1 = spaceDoorPath;
    openDoor2 = beachDoorPath;
  }
}

door1.onclick = () => {
  if(isClicked(doorImage1) === false){
  doorImage1.src = openDoor1;
  playDoor();
  }
}

door2.onclick = () => {
  if(!isClicked(doorImage2)){
  doorImage2.src = openDoor2;
  playDoor();
   }
}

door3.onclick = () => {
  if(!isClicked(doorImage3)){
  doorImage3.src = openDoor3;
  playDoor();
  }
}

const gameOver = (status) => {
  if(status === 'win'){
    startButton.innerHTML = 'You win! Play again?';
  }
}

randomChoreDoorGenerator();


Welcome to the forums.

Please point out in your code where you have defined the object door1, which you are attempting to give an event handler here? :slight_smile:

Hint: You haven’t… because that object doesn’t exist. You’ve got the right idea in that you need to give the doors event handlers for the click… but you’re doing it on the wrong thing.