ChoreDoor js file

Hi, i don’t understand why my code on js file not work.
I search one x one passage and cose but really i can’t find my error.
Can we help me?
Thanks

https://www.codecademy.com/paths/web-development/tracks/build-interactive-websites/modules/web-dev-interactive-websites/projects/chore-door

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

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)) {
    return gameOver('lose')
  }
};
const randomChoreDoorGenerator = () => {
  let 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
  }
};
doorImage1.onclick = () => {
  if(!isClicked(door1) && currentPlaying) {
    doorImage1.src = openDoor1
    playDoor(door1);
  }
};
doorImage2.onclick = () => {
  if(!isClicked(door2) && currentPlaying) {
    doorImage2.src = openDoor2
    playDoor(door2);
  }
};
doorImage3.onclick = () => {
  if(!isClicked(door3) && currentPlaying) {
    doorImage3.src = openDoor3
    playDoor(door3);
  }
};

const startRound = () => {
  numClosedDoors = 3
  currentPlaying = true
  startButton.innerHTML = 'Good Luck!'
  doorImage1.src = closedDoorPath
  doorImage2.src = closedDoorPath
  doorImage3.src = closedDoorPath
  randomChoreDoorGenerator()
};
startButton.onclick = () => {
    if (!currentPlaying) {
        startRound();
    }
};
const gameOver = (status) => {
  if(status === 'win') {
    startButton.innerHTML = 'You win! Play again?'
  } else {
     startButton.innerHTML = 'Game over! Play again?'
  }
   currentPlaying = false
};


startRound()

When you write code you’ll always want to keep an eye on your error log, so where’s that? You’re displaying a web page in your browser, so errors from that web page go into your browser console:

1 Like

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