Chore Dore Project

Whats my mistake? Well I checked my code so many times and I think there is something wrong with the randomChoreDoorGenerator but I can’t find the mistake :confused:

I can open the doors, but everytime I open it there is the bot?

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


let botDoorPath = 'https://s3.amazonaws.com/codecademy-content/projects/chore-door/images/robot.svg'
let beachDoorPath = 'https://s3.amazonaws.com/codecademy-content/projects/chore-door/images/beach.svg'
let spaceDoorPath = 'https://s3.amazonaws.com/codecademy-content/projects/chore-door/images/space.svg'
let closedDoorPath = 'https://s3.amazonaws.com/codecademy-content/projects/chore-door/images/closed_door.svg'

let numClosedDoors = 3;
let openDoor1;
let openDoor2;
let openDoor3;
let startButton = document.getElementById("start");
let currentlyPlaying = true;


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

let isBot = (door) => {
  if (door.src ='https://s3.amazonaws.com/codecademy-content/projects/chore-door/images/robot.svg'){
    return true;
  }
  else return false;
};


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



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

startButton.onclick = () => {if(!currentlyPlaying){
  startRound();}
};

const startRound = () => {
  door1.src = closedDoorPath;
  door2.src = closedDoorPath;
  door3.src = closedDoorPath;
  numClosedDoors = 3;
  currentlyPlaying = true;
  startButton.innerHTML = 'Goodluck!'; 
  randomChoreDoorGenerator();
};

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

startRound();

First door I open is always the bot…

the problem seems to be here:

if (door.src ='https://s3.amazonaws.com/codecademy-content/projects/chore-door/images/robot.svg'){
    return true;
  }

you don’t do a comparison, you do an assign operation.

By doing assign, the string will simple always evaluate as truthy.

Yes it worked! :slight_smile: Thank you so much!
I never would have thought of that.

debugging is a skill all on its own.

1 Like