Chorebot "You win! Play again" message not appearing

I’ve checked the code multiple times and I don’t know why it is still not working step 57. Could you please help me?

let doorImage1 = document.getElementById('door1');
let doorImage2 = document.getElementById('door2');
let doorImage3 = document.getElementById('door3');
let startButton = document.getElementById('start');
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;

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

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

// RANDOM IMAGE BEHIND DOOR
const randomChoreDoorGenerator = () => {
  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{ (choreDoor === 2)
    openDoor3 = botDoorPath
    openDoor1 = beachDoorPath;
    openDoor2 = spaceDoorPath;
    }
}
randomChoreDoorGenerator();

// ON CLICKS

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

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





















Hello @miguelinera,

On this section:

else{ (choreDoor === 2)
    openDoor3 = botDoorPath
    openDoor1 = beachDoorPath;
    openDoor2 = spaceDoorPath;
    }
}

You’re missing the curly brace, it’s in the wrong place, you’re missing a semi-colon, and it won’t read as an else code block because you’ve added a statement:

else  {
    openDoor3 = botDoorPath;
    openDoor1 = beachDoorPath;
    openDoor2 = spaceDoorPath;
    }
} 

That may fix your problem.

In addition to this, if you wanted to use an else block with a statement you’d need to do the following:

let isTrue = false;
if (isTrue) {
  return true;
} else if (!isTrue) {
  return false;
} else {
  return undefined;
}

In practice, the above code block would only use if and else statements and, it could be written more simply as:

const isTrue = val => return val; 

console.log(isTrue(false));

I hope this helps and apologies for the multiple edits.
Best wishes,

Richard.

P.S:

Also in the last function, you’ve coded:

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

Although this may not be causing a problem, be careful with placement of semi-colons. It can sometimes show up as errors:


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

2 Likes

Got it!! Thank you very much for your help. It worked perfectly.

Regarding the else and brackets I also thought it was incorrect, but as I saw it in the explanatory video of the project written like that I thought it was maybe common practice. The semicolons I added them all :slight_smile:

Here the link to the video, min 36:43:

Thanks again!

1 Like

You are most welcome, @miguelinera. Remember don’t pick up bad habits from other people. Strictly speaking, JavaScript should still run without semi colons. Yes, you can forego semi-colons, in the same way you can walk down the street playing very loud music, that is, there is not to prevent you, should you? Probably not!

It is always best to get into the habit of adhering to the syntax of a language. This helps with compatibility. For instance, an unrelated language, Java, requires you to use semicolons and will verbosely tell you that your are missing them.

Happy coding.

1 Like