Chore Door help - game won't reset

Hello,

I’ve just about finished the ChoreDoor project as part of the Web Development path.

My game functions fine, however it does not seem to be able to reset once I’ve played through it once. The startButton does reset the doors to closed when I click on it to play again, however after it has been reset, I cannot click on the doors again without refreshing my browser.

Here is my javascript code, can anyone see where the problem is? (NB: I removed the images because I can only post 2 links as a new user, but they are fine in my original code.)

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

const doorImage2 = document.getElementById(‘door2’);

const doorImage3 = document.getElementById(‘door3’);

const startButton = document.getElementById(‘start’);

const botDoorPath = “projects/chore-door/images/robot.svg”

const beachDoorPath = “projects/chore-door/images/beach.svg”

const spaceDoorPath = “projects/chore-door/images/space.svg”

const closedDoorPath = “projects/chore-door/images/closed_door.svg”;

let numClosedDoors = 3;

let openDoor1;

let openDoor2;

let openDoor3;

let currentlyPlaying = true;

const isBot = (door) => {

if(door.src === botDoorPath){

return true;

} else {

return false;

}

};

const isClicked = (door) => {

if(door.src === closedDoorPath){

return false;

} else {

return true;

}

}

const playDoor = (door) => {

numClosedDoors–;

if (numClosedDoors === 0){

gameOver(‘win’);

} else if (isBot(door)){

gameOver()

}

};

const randomChoreDoorGenerator = () => {

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

if (choreDoor === 0) {

openDoor1 = botDoorPath;

openDoor2 = beachDoorPath;

openDoor3 = spaceDoorPath;

} else if (choreDoor === 1) {

openDoor1 = beachDoorPath;

openDoor2 = botDoorPath;

openDoor3 = spaceDoorPath;

} else {

openDoor1 = beachDoorPath;

openDoor2 = spaceDoorPath;

openDoor3 = botDoorPath;

}

};

door1.onclick = () => {

if(currentlyPlaying && !isClicked(door1)){

doorImage1.src = openDoor1;

playDoor(door1);

}

};

door2.onclick = () => {

if(currentlyPlaying && !isClicked(door2)){

doorImage2.src = openDoor2;

playDoor(door2);

}

};

door3.onclick = () => {

if(currentlyPlaying && !isClicked(door3)){

doorImage3.src = openDoor3;

playDoor(door3);

}

};

startButton.onclick = () => {

if(!currentlyPlaying){

startRound();

}

};

const startRound = () => {

door1.src = closedDoorPath;

door2.src = closedDoorPath;

door3.src = closedDoorPath;

numClosedDoors = 3;

startButton.innerHTML = ‘Good luck!’;

currentPlaying = true;

randomChoreDoorGenerator();

};

const gameOver = (status) => {

if (status === ‘win’) {

startButton.innerHTML = ‘You win! Play again?’;

} else {

startButton.innerHTML = ‘Game over! Play again?’;

}

currentlyPlaying = false;

};

startRound();

Hello, and welcome to the forums

You have currentlyPlaying and currentPlaying variables right now, so it isn’t truly resetting when you call startRound() again

1 Like

OK I see now.

Thanks for that!