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

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

I strictly followed all the steps, but now every door should open with a different image, and it is not working. Can someone help me notice whats going on in my code, please?

//Global variables

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";

//global variables for the randombotImage

let numClosedDoors = 3;

let openDoor1 = 

let openDoor2 = 

let openDoor3 =

//END OF GLOBAL VARIABLES

//function to randomlly alocate the bot

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;

      }

};

//functions to open the doors

///door1

doorImage1.onclick = () => {

doorImage1.src = openDoor1;

}

//door2

doorImage2.onclick = () => {

doorImage2.src = openDoor2;

}

//door3

doorImage3.onclick = () => {

doorImage3.src = openDoor3;

}

randomChoreDoorGenerator()

So one could say that they’d want images to show randomly. That would point us towards a line that is responsible for it.

Currently, you should be getting the following error

ReferenceError: math is not defined
  randomChoreDoorGenerator

The JavaScript exception “variable is not defined” occurs when there is a non-existent variable referenced somewhere. However, math shouldn’t be a variable, but a built-in object.


Also, are you sure that this is correct?

let openDoor1 = 

let openDoor2 = 

let openDoor3 =

You’re almost there, keep going!

Yes, I am sure, it is exactly what the lesson told me to do. :frowning:

hy,i’m currently having the same problem,they used to open and at some point in java,they wouldn’t open anymore,and followed everything exactly. I was curious to see how have you managed it after all

1 Like