Chore Door Help

Hello everyone,

Can someone help me with chore door? I got it working up to a certain point. I had to change one }else{ to }else if{ to get it working… But I cannot get my doors to open at all again.

let doorImage1 = document.getElementById(‘door1’);

let doorImage2 =
document.getElementById(‘door2’);
let doorImage3=
document.getElementById(‘door3’);
const startButton =
document.getElementById(‘start’);
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”;

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

const playDoor = () =>{
numClosedDoors–;
if (numClosedDoors === 0){
gameOver(‘win’);
}
};

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

doorImage1.onclick = ()=> {
if(!isClicked(doorImage1)) {
doorImage3.src = openDoor1;
playDoor();
}};

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

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

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

randomChoreDoorGenerator();

changed my door images. still nothing.

That and the one following both point to #3. Change to 1 and 2 as apply.

1 Like

I found another mistake: isClicked should be isClick.

You are always so helpful on these forums! Thanks!

Also, we should have a thread with ALL the answers to ALL the projects. So that we can all have a reference point.

1 Like