Chore Door Project: Step 57

Hi all. Can someone please review my code? What am I doing wrong? My doors opened at task 45, but they don’t any more.

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 isClicked = (door) => {
  if (door.src === closedDoorPath) {
     return false;
  } else {
     return true;
  }
}


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

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

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();
  }
}
let gameOver = (status) => {
   if(status === 'win') {
     startButton.innerHTML = 'You win! Play again?';
   }
}
randomChoreDoorGenerator();

Hi Hanna,
you have a syntax error here:

the syntax for if else is like this:

if(condition){}
else if(condition){}
else{}

Then there is this error message:

Uncaught TypeError: document.getElementbyId is not a function"

Occurring on the line where you define startButton.

Thank you Marja! That fixed the issue.

1 Like

this is the entire working code posted to gitHub, cheers.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.