Https://www.codecademy.com/paths/web-development/tracks/build-interactive-websites/modules/web-dev-interactive-websites/projects/chore-door

Hello I followed the steps and I am stuck on step 57. My code isn’t working as doors are still closed even when I clicked on it and I am confused why. Can someone help me please?

let doorImage1 = document.getElementById('door1');

let startButton = document.getElementById('start');
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 numClosedDoors = 3;
let openDoor1;
let openDoor2;
let openDoor3;
let closedDoorPath = "https://s3.amazonaws.com/codecademy-content/projects/chore-door/images/closed_door.svg";



const isClicked = (door) => {
 if(door.src === closedDoorPath) {
   return false;
 }
 else {
   return true;
 }
}
const playDoor = () => {
  numClosedDoors--;
  if(numClosedDoors === 0) {
    gameOver('win');
  }

}

doorImage1.onclick = () => {
if(!isClicked(doorImage1)) {
 
doorImage1.src = openDoor1;
 playDoor(doorImage1);
}
};
let doorImage2 = document.getElementById('door2');
doorImage2.onclick = () => {
 if(!isClicked(doorImage1)) {

 doorImage2.src = openDoor2;
  playDoor(doorImage2);
}
};
let doorImage3 = document.getElementById('door3');
doorImage3.onclick = () => {
 if(!isClicked(doorImage1)) {
  
  doorImage3.src = openDoor3;
   playDoor(doorImage3);
}
}
const gameOver = (status) => {
if (status === 'win') {
  startButton.innerHTML = 'You win! Play again?';
}
};

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





`

Can you provide the exercise url?

The first step could be to use the console (f12 is generally the shortcut), to see if you have any errors.

the console is a useful debug tool. So using the console is highly recommended.

1 Like

https://www.codecademy.com/paths/web-development/tracks/build-interactive-websites/modules/web-dev-interactive-websites/projects/chore-door

Thank for you the support. I found the issue when I use if(!isClicked(doorImage1)) for doorImage1 , doorImage2, and doorImage3. So I changed it to each own door number and works now.

1 Like