Choredoor - doors not opening

Hello all,

Ok so towards the beginning all 3 doors used to open but as I started adding codes, now even though the cursor does switch to pointer, the doors don’t open. I am comparing my code with the walkthrough code and it looks the same.

anyone can help me please. (let me know if posting my code here would be helpful :slight_smile: )

Hey there, welcome to the forums!

Yes, that definitely would help.

You can paste it here and use code formatting.


To format your code, simply press this button:

Then copy / paste your code between the backticks:

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

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

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

let closedDoorPath = 'https://content.codecademy.com/projects/chore-door/images/closed_door.svg'

let numClosedDoors = 3;

let openDoor1;
let openDoor2;
let openDoor3;

let currentPlaying = true;


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


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)) {
    gameOver('lose');
  } 
}


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

startButton.onclick = () => {
  startRound();
}

const startRound = () => {
  doorImage1.src = closedDoorPath;
  doorImage2.src = closedDoorPath;
  doorImage3.src = closedDoorPath;
  numClosedDoors = 3;
  currentlyPlaying = true;
  startButton.innerHTML: = 'GOOD LUCK!';
}

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

I hope I did it right :blush:

1 Like

I figured it out thank you :slight_smile:

1 Like