Chore door :@

The door suddenly stopped opening up. I’m stuck again with this project. The walktrough video is a complete rubbish, even the code they give is not working. I made a mistake here in this code somewhere but I’m not able to find it once again and there is no option by codeacademy to search for it automatically.

Please if you se anything wrong tell me.
I am at task 63. Like 2-3 task before the everything was working fine. Now its stuck…

Thanks for the help!!

best wishes,

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

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

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

//global veriable for doorimage connecting to the elements of html with id door1,door2,door3

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

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”;

//give an src to a variable so we can us later in the function easily

const closedDoorPath = “https://content.codecademy.com/projects/chore-door/images/closed_door.svg”;

let openDoor1;

let openDoor2;

let openDoor3;

numClosedDoors = 3;

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

}

} //this functions works for the first image, changes the first global variables src to butDoorPaths src.

doorImage2.onclick = ()) => {

if(!isClicked(doorImage2)) {

doorImage2.src = openDoor2;

playDoor(doorImage2);

}

}

doorImage3.onclick = () => {

if(!isClicked(doorImage3)) {

doorImage3.src = openDoor3;

playDoor(doorImage3);

}

}

const gameOver = (status) => {

if (status === ‘win’) {

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

} else {

startButton.innerHTML = 'Game over! Play again?'

}

}

randomChoreDoorGenerator();

You have an extra ) there :upside_down_face:

1 Like

I was searching for it everywhere else. Rewriting the code several times :grimacing: :grimacing: :grimacing:

I guess it was enough for today :smiley: thanks though!!

2 Likes

Haha, yeah, giving your brain a break is always important :wink:
Glad I could help :blush:

your browser ships with a console (f12 is generally the hot/short-key -> then console tab)

The console can display errors which can help you debug your code.

1 Like