Chore Door stuck somewhere after ifClicked

Over at Chore Door https://www.codecademy.com/courses/build-interactive-websites/projects/chore-door

I can’t make the doors open, it happened somewhere at of after step 53, any help please?

//connection doors to html 
let doorImage1 = document.getElementById ("door1");

let doorImage2 = document.getElementById ("door2");

let doorImage3 = document.getElementById ("door3");

//images behind doors
let botDoorPath = "https://content.codecademy.com/projects/chore-door/images/robot.svg";

let beachDoorPath = "https://content.codecademy.com/projects/chore-door/images/beach.svg";

let spaceDoorPath = "https://content.codecademy.com/projects/chore-door/images/space.svg";

//set number of doors
let numClosedDoors = 3;

//doors open
let openDoor1;
let openDoor2;
let openDoor3;

//door closed
let closedDoorPath = ("https://content.codecademy.com/projects/chore-door/images/closed_door.svg");

let startButton = document.getElementById("start");

//check if all doors are clicked - game winning condition
let playDoor = () => {
  numClosedDoors--;
  if (numClosedDoors === 0) {
    gameOver('win');
  }
};

//checking if door opened once to prevent cheating by clicking many times on same door || game from shortcut victories by making each closed door clickable only once. 
let isClicked = () => {
  if (door.src === closedDoorPath) {
    return false;
  } else {
    return true;
  }
};

//randomise the doors
let randomChoreDoorGenerator = () => {
  let choreDoor = Math.floor(Math.random() * numClosedDoors);
  if(choreDoor === 0) {
    openDoor1 = botDoorPath;
    openDoor2 = beachDoorPath;
    openDoor3 = spaceDoorPath;
  } else if (choreDoor === 1) {
    openDoor2 = botDoorPath;
    openDoor1 = beachDoorPath;
    openDoor3 = spaceDoorPath;
  } else if (choreDoor === 2) {
    openDoor3 = botDoorPath;
    openDoor1 = beachDoorPath;
    openDoor2 = spaceDoorPath;
  }
};

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

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

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

doorImage3.onclick = () => {
  if(!isClicked(doorImage3)) {
    doorImage3.src = openDoor3;
    playDoor();
  }
};

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

};

//call of random doors functions
randomChoreDoorGenerator();

Hi Farid,
when you have a problem like this, I’d recommend to take a look at the console. Even though this project’s sandbox doesn’t provide any (given you develop online), you can still use the browser’s console. It throws this error:

Uncaught ReferenceError: door is not defined

This is where it occurs:

you did not declare the variable door anywhere. And the function isClicked does not have a parameter. Although here:

You call it with an argument.

Once you corrected that you’ll encounter more error like that which you could also solve by tracing back the variables in question. If you’re still stuck, let me know.

1 Like

Thanks, I will definitely keep an eye on the console from now on. :slight_smile:

I have have hit another rod block though, I can’t seem make the game to gameOver().

//connection doors to html 
let doorImage1 = document.getElementById ("door1");

let doorImage2 = document.getElementById ("door2");

let doorImage3 = document.getElementById ("door3");

//images behind doors
let botDoorPath = "https://content.codecademy.com/projects/chore-door/images/robot.svg";

let beachDoorPath = "https://content.codecademy.com/projects/chore-door/images/beach.svg";

let spaceDoorPath = "https://content.codecademy.com/projects/chore-door/images/space.svg";

//set number of doors
let numClosedDoors = 3;

//doors open
let openDoor1;
let openDoor2;
let openDoor3;

//door closed
let closedDoorPath = ("https://content.codecademy.com/projects/chore-door/images/closed_door.svg");

let startButton = document.getElementById("start");

let currentlyPlaying = true;

//check if all doors are clicked - game winning condition
let playDoor = () => {
  numClosedDoors--;
  if (numClosedDoors === 0) {
    gameOver('win');
  } else if (isBot(door)) {
    gameOver();
  }
};

// Checks if bot is in selected door
let isBot = (door) => {
  if (door.src === botDoorPath) {
    return true;
  } else {
    return false;
  }
};

//checking if door opened once to prevent cheating by clicking many times on same door || game from shortcut victories by making each closed door clickable only once. 
let isClicked = (door) => {
  if (door.src === closedDoorPath) {
    return false;
  } else {
    return true;
  }
};



//randomise the doors
let randomChoreDoorGenerator = () => {
  let choreDoor = Math.floor(Math.random() * numClosedDoors);
  if(choreDoor === 0) {
    openDoor1 = botDoorPath;
    openDoor2 = beachDoorPath;
    openDoor3 = spaceDoorPath;
  } else if (choreDoor === 1) {
    openDoor2 = botDoorPath;
    openDoor1 = beachDoorPath;
    openDoor3 = spaceDoorPath;
  } else if (choreDoor === 2) {
    openDoor3 = botDoorPath;
    openDoor1 = beachDoorPath;
    openDoor2 = spaceDoorPath;
  }
};

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

//call of random doors functions
randomChoreDoorGenerator();

The console still complains about an undefined door:

Therefore this condition cannot be true.

I am not getting this error… :man_shrugging:

I am following the hint though.

In the last version you posted you pass door as an argument to the isBot function. But door is not defined anywhere. Therefore as soon as you click a door playDoor is called and throws the error. It is the same issue as before: You call the function playDoor with an argument but the function does not accept any arguments.

I guess I’m stuck… any hints?

Here (and in two other onclick functions) you call the function with the argument isBot should receive:

But it is not passed through…

All done:

//connection doors to html 
let doorImage1 = document.getElementById ("door1");

let doorImage2 = document.getElementById ("door2");

let doorImage3 = document.getElementById ("door3");

//images behind doors
let botDoorPath = "https://content.codecademy.com/projects/chore-door/images/robot.svg";

let beachDoorPath = "https://content.codecademy.com/projects/chore-door/images/beach.svg";

let spaceDoorPath = "https://content.codecademy.com/projects/chore-door/images/space.svg";

//set number of doors
let numClosedDoors = 3;

//doors open
let openDoor1;
let openDoor2;
let openDoor3;

//door closed
let closedDoorPath = ("https://content.codecademy.com/projects/chore-door/images/closed_door.svg");

let startButton = document.getElementById("start");

let currentlyPlaying = true;

// Checks if bot is in selected door
let isBot = (door) => {
  if (door.src === botDoorPath) {
    return true;
  } else {
    return false;
  }
};

//checking if door opened once to prevent cheating by clicking many times on same door || game from shortcut victories by making each closed door clickable only once. 
let isClicked = (door) => {
  if (door.src === closedDoorPath) {
  return false;
    } else {
      return true;
    }
};

//check if all doors are clicked - game winning condition
let playDoor = (door) => {
  numClosedDoors--;
  if (numClosedDoors === 0) {
    gameOver('win');
  } else if (isBot(door)) {
    gameOver();
  }
};

//randomise the doors
let randomChoreDoorGenerator = () => {
  let choreDoor = Math.floor(Math.random() * numClosedDoors);
  if(choreDoor === 0) {
    openDoor1 = botDoorPath;
    openDoor2 = beachDoorPath;
    openDoor3 = spaceDoorPath;
  } else if (choreDoor === 1) {
    openDoor2 = botDoorPath;
    openDoor1 = beachDoorPath;
    openDoor3 = spaceDoorPath;
  } else if (choreDoor === 2) {
    openDoor3 = botDoorPath;
    openDoor1 = beachDoorPath;
    openDoor2 = spaceDoorPath;
  }
};

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

let startRound = () => {
  numClosedDoors = 3;
  doorImage1.src = closedDoorPath;
  doorImage2.src = closedDoorPath;
  doorImage3.src = closedDoorPath;
  startButton.innerHTML = "Good luck!";
  currentlyPlaying = 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;
};

//call of random doors functions
startRound();
1 Like