Chore Door project step 57

let doorImage1 = document.getElementById('door1');
let doorImage2 = document.getElementById('door2');
let doorImage3 = document.getElementById('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";
const closedDoorPath = 'https://content.codecademy.com/projects/chore-door/images/closed_door.svg'
const numClosedDoors = 3;
let openDoor1;
let openDoor2;
let openDoor3;

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;
    openDoor1 = beachDoorPath;
    openDoor3 = spaceDoorPath;
  } else { 
    openDoor3 = botDoorPath;
    openDoor1 = beachDoorPath;
    openDoor2 = spaceDoorPath;
  }
}

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

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

randomChoreDoorGenerator();

innerhtml of button is not changing after all doors are open, i couldn’t figure out why ?

Could you post your html as well?

Ok I dont’t think that’s necessary. I see a problem. What does your console say?

Thanks again @mirja_t , i figured out, numcloseddoors should be let.

Yes. If you have problems like that and the codecademy console is not really helpful, try fiddle. The error messages are very detailed and the editor is also showing you when you’re trying to override a const.

1 Like