Chore door - step 57

Hi all!
I am working on the project “Chore doors”, but I’m stuck trying to implement step 57. The description says, the start button should change when the winning condition is reached, but nothing happens. Console didn’t help, since I cannot adequately interpret. I will present the code that i have collected so far:


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

const botDoorPath =
  "https://s3.amazonaws.com/codecademy-content/projects/chore-door/images/robot.svg";
const beachDoorPath =
  "https://s3.amazonaws.com/codecademy-content/projects/chore-door/images/beach.svg";
const spaceDoorPath =
  "https://s3.amazonaws.com/codecademy-content/projects/chore-door/images/space.svg";

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

let openDoor1;

let openDoor2;

let openDoor3;

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

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

const playDoor = door => {
  numClosedDOoors--;
  if (numClosedDoors === 0) {
    gameOver("win");
  }
}

const randomChoreDoorGenerator = () => {
  let numClosedDoors = 3;
  const choreDoor = Math.floor(Math.random() * numClosedDoors);
  if (choreDoor === 0) {
      openDoor1 = botDoorPath;
      openDoor2 = beachDoorPath;
      openDoor3 = spaceDoorPath;
  } else if (choreDoor === 1) {
      openDoor2 = botDoorPath;
      openDoor3 = beachDoorPath;
      openDoor1 = spaceDoorPath;
  } else if (choreDoor === 2) {
      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();
}}

randomChoreDoorGenerator();

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

Thanks for help, Yves

project url: https://www.codecademy.com/courses/build-interactive-websites/projects/chore-door

The error in the console is:

Uncaught ReferenceError: numClosedDOoors is not defined

Look at the variable name, does that look right to you? I see triple o.

Thank you a lot! There was indeed such a fault at the const playDoor variable. After removing it, still when I win, the start button doesn’t change! There must be another fault! Help!

No console error? Could you post an updated version of your code?

Fore sure! Here it is and I will add, what kind of error jsfiddle console finds:


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

const botDoorPath =
  "https://s3.amazonaws.com/codecademy-content/projects/chore-door/images/robot.svg";
const beachDoorPath =
  "https://s3.amazonaws.com/codecademy-content/projects/chore-door/images/beach.svg";
const spaceDoorPath =
  "https://s3.amazonaws.com/codecademy-content/projects/chore-door/images/space.svg";

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

let openDoor1;

let openDoor2;

let openDoor3;

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

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

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

const randomChoreDoorGenerator = () => {
  let numClosedDoors = 3;
  const choreDoor = Math.floor(Math.random() * numClosedDoors);
  if (choreDoor === 0) {
      openDoor1 = botDoorPath;
      openDoor2 = beachDoorPath;
      openDoor3 = spaceDoorPath;
  } else if (choreDoor === 1) {
      openDoor2 = botDoorPath;
      openDoor3 = beachDoorPath;
      openDoor1 = spaceDoorPath;
  } else if (choreDoor === 2) {
      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();
}}

randomChoreDoorGenerator();

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















jsfiddle:

"<a class='gotoLine' href='#187:3'>187:3</a> ReferenceError: numClosedDoors is not defined"

still a problem in your playdoor function:

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

numClosedDoors is undefined. This is scope related. numClosedDoors is block-scoped in the randomChoreDoorGenerator function:

const randomChoreDoorGenerator = () => {
  let numClosedDoors = 3;

so now we can’t access this variable outside the function.

Oh! Thank you for your really quick answer! Guess I have to review my code and put the variable outside somehow…

step 38 indeed seems to recommend using a global variable:

This function will require many new global variables in order for the game’s logic to work.

Create the global variable numClosedDoors and set its value to the amount of doors in the game.

1 Like

Now, the start button is changing when I win! yay! Thank you so much :slight_smile:
:robot:

guys i am also stuck in chore door please help me i am on step 62 and here is the code

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

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 botDoorPath = 'https://content.codecademy.com/projects/chore-door/images/robot.svg';

let openDoor1;
let openDoor2;
let openDoor3;

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

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

let numClosedDoors = 3; 

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

const randomChoreDoorGenerator = () => { 
set 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; 
openDoor2 = beachDoorPath; 
openDoor1 = spaceDoorPath; 
}
}

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

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

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

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

randomChoreDoorGenerator();

i tested my javascript code in an editor it gave me this error i do not know how to solve it here is the error

error: unknown: Unexpected token (90:27)

  88 | }; 
  89 | 
> 90 | randomChoreDoorGenerator();
     |                            ^

I get very different errors, like:

const randomChoreDoorGenerator = () => { 
  console.log('get here');
set choreDoor = Math.floor(Math.random() * numClosedDoors); 

why do you use set keyword here?

and this opening curly bracket:

const isBot = (door) => { 

from function isn’t closed anywhere

wow thank you soooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo much it works
:smiley:

yay finnaly finished :smiley: :smiley: the chore door project