HI, could someone post the bug-free full code of the Chore Door Challenge on the Interactive JavaScript Websites? My code is here, but somehow the doors won’t open:
let doorImage1 = document.getElementById('door1');
let doorImage2 = document.getElementById("door2");
let doorImage3 = document.getElementById("door3");
let startButton = document.getElementbyId("start");
let numClosedDoors = 3;
let openDoor1;
let openDoor2;
let openDoor3;
let currentPlaying = true;
let closedDoorPath = "https://s3.amazonaws.com/codecademy-content/projects/chore-door/images/closed_door.svg";
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)=== true) {
gameOver();
}
}
const randomChoreDoorGenerator = () => {
let choreDoor = Math.floor(Math.random() *numClosedDoors);
if (choreDoor === 1) {
openDoor1 = botDoorPath;
openDoor2 = beachDoorPath;
openDoor3 = spaceDoorPath;
} else if (choreDoor === 2) {
openDoor2 = botDoorPath;
openDoor1 = beachDoorPath;
openDoor3 = spaceDoorPath;
} else if (choreDoor === 3) {
openDoor3 = botDoorPath;
openDoor2 = spaceDoorPath;
openDoor1 = beachDoorPath;
}
}
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";
const startRound = () => {
doorImage1.src = closedDoorPath;
doorImage2.src = closedDoorPath;
doorImage2.src = closedDoorPath;
numClosedDoors = 3;
doorImage.src = closedDoorPath;
startButton.innerHTML = 'Good Luck';
currentPLaying = true;
randomChoreDoorGenerator();
}
startButton.onclick = () => {
if(currentlyPlaying === false) {
startRound() {
}
}
const gameOver = (status) => {
if(status === 'win') {
startButton.innerHTML = 'You win! Play again?';
} else {
startButton.innerHTML = 'Game over! Play again?';
}
currentlyPlaying = false;
}
door1.onclick = () => {
if(currentlyPLaying && !isClicked(doorImage1)) {
doorImage1.src = openDoor1;
}
playDoor(door1);
}
door2.onclick = () => {
if(currentlyPLaying && !isClicked(doorImage2)) {
doorImage2.src = openDoor2;
}
playDoor(door2);
}
door3.onclick = () => {
if(currentlyPLaying && !isClicked(doorImage3)) {
doorImage3.src = openDoor3;
}
playDoor(door3);
}
startRound();
https://www.codecademy.com/courses/build-interactive-websites/projects/chore-door
Thank you!