Hi guys, Im stuck on the Chore Door project. Im up to part 58 and cant figure out why my “Good Luck!” button at the bottom of the 3 doors wont change to “You win! Play again?” string. Im sure i’ve done something silly here, but I cant quite figure it out.
// Delcaring global variables
const numClosedDoors = 3;
let openDoor1;
let openDoor2;
let openDoor3;
let startButton = document.getElementById('start');
// Declaring functions
let randomChoreDoorGenerator = () => {
const choreDoor = Math.floor(Math.random() * numClosedDoors);
if (choreDoor === 0){
openDoor1 = botDoorPath;
openDoor2 = beachDoorPath;
openDoor3 = spaceDoorPath;
}
else if (choreDoor === 1){
openDoor2 = botDoorPath;
openDoor3 = beachDoorPath;
openDoor1 = spaceDoorPath;
}
else if (choreDoor === 2){
openDoor3 = botDoorPath;
openDoor1 = beachDoorPath;
openDoor2 = spaceDoorPath;
}
};
const isClicked = door => {
if(door.src === closedDoorPath){
return false;
}
else{
return true;
}
};
const playDoor = (door) => {
numClosedDoors--;
if (numClosedDoors === 0){
gameOver('win');
}
};
const gameOver = (status) => {
if (status === 'win'){
startButton.innerHTML = 'You win! Play again?';
}
};
// Using Get Element to find the respective doors in Index.html
const doorImage1 = document.getElementById('door1');
const doorImage2 = document.getElementById("door2");
const doorImage3 = document.getElementById("door3");
// Setting each door path an image
const botDoorPath = "https://content.codecademy.com/projects/chore-door/images/robot.svg";
const beachDoorPath = "https://content.codecademy.com/projects/chore-door/images/beach.svg";
const spaceDoorPath = "https://content.codecademy.com/projects/chore-door/images/space.svg";
const closedDoorPath = "https://content.codecademy.com/projects/chore-door/images/closed_door.svg";
// Creating the function to change the door image when we click it
let door1click = doorImage1.onclick = () => {
if(!isClicked(doorImage1)){
doorImage1.src=openDoor1;
playDoor();
}
};
let door2click = doorImage2.onclick = () => {
if(!isClicked(doorImage2)){
doorImage2.src=openDoor2;
playDoor();
}
};
let door3click = doorImage3.onclick = () => {
if(!isClicked(doorImage3)){
doorImage3.src=openDoor3;
playDoor();
}
};
// Call the games function
randomChoreDoorGenerator();