Chore Bot Problem

I’ve completed the Task 65 however I can still open the remaining doors and override a loss to victory. Please see my codes below. Any help would be very great!

const doorImage1 = document.getElementById('door1');
const doorImage2 = document.getElementById('door2');
const doorImage3 = document.getElementById('door3');

const startButton = document.getElementById('start');

const currentlyPlaying = true;

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

let numClosedDoors = 3;

let openDoor1;
let openDoor2;
let openDoor3;

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

const isBot = (door) => {
    return door.src === botDoorPath ? true : false;
}

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

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

const randomChoreDoorGenerator = () => {
    let choreDoor = Math.floor(Math.random() * numClosedDoors);
    switch(choreDoor) {
        case 0:
            openDoor1 = botDoorPath;
            openDoor2 = beachDoorPath;
            openDoor3 = spaceDoorPath;
            break;
        case 1:
            openDoor2 = botDoorPath;
            openDoor1 = beachDoorPath;
            openDoor3 = spaceDoorPath;
            break;
        case 2:
            openDoor3 = botDoorPath;
            openDoor1 = beachDoorPath;
            openDoor2 = spaceDoorPath;
            break;
    }
}

doorImage1.onclick = () => {
    if (currentlyPlaying && !isClicked(doorImage1)) {
    doorImage1.src = openDoor1;
    playDoor(doorImage1);
}
}

doorImage2.onclick = () => {
    if (currentlyPlaying && !isClicked(doorImage2)) {
    doorImage2.src = openDoor2;
    playDoor(doorImage2);
}
}

doorImage3.onclick = () => {
    if (currentlyPlaying && !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?';
}
    currentlyPlaying = false;
}

randomChoreDoorGenerator();

Try playing the game with your browser console open. You may see an error or few. You can also use console.log() statements in your code to observe what is happening. The output will appear in your browser console. Including a link to the project in your post would be helpful as well.

1 Like

Found the problem. I used const currentlyPlaying instead of let currentlyPlaying which is preventing the gameOver function to reassign currentlyPlaying variable. Thank you!

1 Like