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();