Stuck on Chore Door project

Hi,
I was working on the Chore Door assignment (https://www.codecademy.com/paths/web-development/tracks/build-interactive-websites/modules/web-dev-interactive-websites/projects/chore-door) and got completely stuck somewhere after task 37. Watching the added video three times hasn’t helped (besides that the instructor in that video copy pastes the hints a lot) and customer support won’t/can’t give me the javascript code so I can check where I went wrong.

Does someone have the proper JS code for Chore Door project for me so can I find my error and move on?

Cheers,
Jaap

Hey there!

It’s not really policy in the forum to share answer code but we can definitely try and help you find your problem. (And error detection is a huge part of these projects, so it’s part of the learning process).

Just share your code (remember to format with </>) and any relevant error messages or unexpected results.

Thanks toastedpitabread, I’m used to a commercial application like Codecademy actually offering the answers to assignments (not an official test, just a homework assignment). But if you can help me out that would be great.

The fault in my code should be in the javascript below somewhere, as the HTML and CSS code was made earlier and worked properly.

let doorImage1 = document.getElementById(‘door1’);
let doorImage2 = document.getElementById(‘door2’);
let doorImage3 = document.getElementById(‘door3’);
let startButton = document.getElementById(‘start’);
const botDoorPath = “https://s3.amazonaws.com/codecademy-content/projects/chore-door/images/robot.svg”;
const beachDoorPath = “https://s3.amazonaws.com/codecademy-content/projects/chore-door/images/beach.svg”;
const spaceDoorPath = “https://s3.amazonaws.com/codecademy-content/projects/chore-door/images/space.svg”;
let numClosedDoors = 3;
let openDoor1;
let openDoor2;
let openDoor3;
let closedDoorPath = "https://s3.amazonaws.com/codecademy-content/projects/chore-door/images/closed_door.svg”;

const isClicked = (door) => {
if (door.src === closedDoorPath) {
return false;
} else {
return true;
}
}

const playDoor = () = {
numClosedDoors–;
if (numClosedDoors === 0) {
gameOver(‘win’);
}
}

const 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 { (choreDoor === 2)
openDoor3 = botDoorPath;
openDoor1 = beachDoorPath;
openDoor2 = spaceDoorPath;
}
}

door1.onclick = () => {
if (!isClicked(doorImage1)) {
doorImage1.src = openDoor1;
playDoor();
}
}
door2.onclick = () => {
if (!isClicked(doorImage2)) {
doorImage2.src = openDoor2;
playDoor();
}
}
door3.onclick = () => {
if (!isClicked(doorImage3)) {
doorImage3.src = openDoor3;
playDoor();
}
}

const gameOver = (status) => {
if (status === ‘win’) {
startButton.innerHTML = ‘You win! Play again?’;
}
}

randomChoreDoorGenerator();

There are many syntax errors in this program; missing semicolons, improperly placed conditionals, improperly defined functions.

Resolve those first, then you can re-examine function.

Hey thanks 825orion, I’ve checked and used the project walkthrough as an example. I noticed the instructor there did some things different (and I understand some rules have relaxed with recent js versions) but her code - without the semicolons etc - worked in the project walkthrough.

I attempted to run your code and was unable to do so because of the syntax errors… maybe a version differential. I’ve resolved the errors on my end, and it looks like this:

let doorImage1 = document.getElementById('door1');
let doorImage2 = document.getElementById('door2');
let doorImage3 = document.getElementById('door3');
let startButton = document.getElementById('start');
const botDoorPath = "https://s3.amazonaws.com/codecademy-content/projects/chore-door/images/robot.svg";
const beachDoorPath = "https://s3.amazonaws.com/codecademy-content/projects/chore-door/images/beach.svg";
const spaceDoorPath = "https://s3.amazonaws.com/codecademy-content/projects/chore-door/images/space.svg";
let numClosedDoors = 3;
let openDoor1;
let openDoor2;
let openDoor3;
let closedDoorPath = "https://s3.amazonaws.com/codecademy-content/projects/chore-door/images/closed_door.svg";

const isClicked = (door) => {
    if (door.src === closedDoorPath) {
        return false;
    } else {
        return true;
    }
};

const playDoor = () => {
    numClosedDoors--;
    if (numClosedDoors === 0) {
        gameOver('win');
    }
};

const 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;
    }
};

door1.onclick = () => {
    if (!isClicked(doorImage1)) {
        doorImage1.src = openDoor1;
        playDoor();
    }
};
door2.onclick = () => {
    if (!isClicked(doorImage2)) {
        doorImage2.src = openDoor2;
        playDoor();
    }
};
door3.onclick = () => {
    if (!isClicked(doorImage3)) {
        doorImage3.src = openDoor3;
        playDoor();
    }
};

const gameOver = (status) => {
    if (status === 'win') {
        startButton.innerHTML = 'You win! Play again?';
    }
};

randomChoreDoorGenerator();

At this point, I encounter errors where you define functionality for a click on each door: You do not define door1, door2, or door3. Are these typos that are meant to be other variables?

I suspect you mean the doorImage variables instead (as they reference the HTML image elements).

After this point, you’ll need to attach the HTML (and preferably the CSS) code you’re using; otherwise there are no elements for the code to reference, and we’ll be unable to help you debug.

Be sure when sharing here to format the code with the </> before you paste also, it will make a huge difference in people being able to read it and help :slight_smile:

1 Like

Thanks 825orion, your code works and helped me find a few few typos in my code. It doesn’t do what it’s supposed to do however. I’m gonna ask customer support for the proper code from the CodeCademy (they should have it), and meanwhile continue with next chapters. I want to find my mistakes, but looking for them has taken me hours already and it’s losing it’s point by now.
Thanks again, Jaap