Chore door stuck

Dear everyone!

Once again I’m stuck with this project. So far my code is mostly the same as in the walktrough video(which is btw a disaster by my opinion), however, after reaching task 57, which should change the start button to a message “You win! Play again?” does not work. But I did the code the same way as in the example, still doesn seem to work it doesnt changes and now I can go forward again.

Please have a look at my code and if you have any idea share with me. Thanks a lot!
Here is my code :

let isClicked = (door) => {

if (door.src === closedDoorPath) {

return false

} else {

return true

}

}

let playDoor = () => {

numClosedDoors --;

if (numClosedDoor === 0) {

gameOver('win');

}

}

const randomChoreDoorGenerator = () => {

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

if (choreDoor === 0){

openDoor3 = botDoorPath;

openDoor2 = beachDoorPath;

openDoor1 = spaceDoorPath;

} else if (choreDoor === 1) {

openDoor1 = botDoorPath;

openDoor2 = beachDoorPath;

openDoor3 = spaceDoorPath;

} if (choreDoor === 2) {

openDoor2 = botDoorPath;

openDoor3 = beachDoorPath;

openDoor1 = spaceDoorPath;

}

}

doorImage1.onclick = () => {

if(!isClicked(doorImage1)) {

doorImage1.src = openDoor1;

playDoor();

}

}

doorImage2.onclick = () => {

if(!isClicked(doorImage2)) {

doorImage2.src = openDoor2;

playDoor();

}

}

doorImage3.onclick = () => {

if(!isClicked(doorImage3)) {

doorImage3.src = openDoor3;

playDoor();

}

}

let gameOver = (status) => {

if (status === ‘win’) {

startButton.innerHTML = 'You win! Play again?';

}

}

randomChoreDoorGenerator();

Hi there! I’m not sure if this will fix it, but you have a typo:


let playDoor = () => {

numClosedDoors --;

if (numClosedDoor === 0) {

gameOver('win');
}

}

First you are subtracting 1 from numClosedDoors (with an s at the end). Then when you check if that variable equals 0, you write numClosedDoor (without an s).

1 Like

Uffff :laughing: I’m so blind to find the little errors. Thanks a lot it solved it!

1 Like

Yay! :grin:
Don’t worry, that happens to me all the time :sweat_smile:

It happens so often, it’s the first thing I look for in my code when I get an error :laughing:

1 Like