Javascript - Chore Bot project - Task 45

Hi Everyone,

I’m stumped on this project here since last night.
Everything was going well up until I got to task 45 where I’m supposed to check that my onclick.() functions work by generating a random image behind one of the 3 doors.

I have closely inspected my code but I cannot seem to pinpoint the issue.

It seems that this issue lies within randomChoreDoorGenerator function.
I noticed for some reason the left parenthesis is always blue and not white as it should be.

What am I doing wrong?

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

// Variables containing images
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 numClosedDoors = 3;
let openDoor1;
let openDoor2;
let openDoor3;

// Generates random number with conditional statement for placing images randomly behind doors
const randomChoreDoorGenerator= () => {
  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 (choreDoor === 2) {
    openDoor3 = botDoorPath;
    openDoor1 = beachDoorPath;
    openDoor2 = spaceDoorPath;
  } 
  };

// Opens Door On Click
door1.onclick = () => {
  doorImage1.src = openDoor1;
};

door2.onclick = () => {
  doorImage2.src = openDoor2;
};

door3.onclick = () => {
  doorImage3.src = openDoor3;
};

randomChoreDoorGenerator();
2 Likes

So I’ve been using the DEV TOOLS and found one error which involved my else statement.

Now when I click, the door changes but it’s an empty image.
I’ll need to figure out this next piece now.

Any assistance is greatly appreciated though.

Updated code:

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

// Variables containing images
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 numClosedDoors = 3;
let openDoor1;
let openDoor2;
let openDoor3;

// Generates random number with conditional statement for placing images randomly behind doors
const randomChoreDoorGenerator= () => {
  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 { (choreDoor === 2) 
    openDoor3 = botDoorPath;
    openDoor1 = beachDoorPath;
    openDoor2 = spaceDoorPath;
  } 
  };

// Opens Door On Click
door1.onclick = () => {
  doorImage1.src = openDoor1;
};

door2.onclick = () => {
  doorImage2.src = openDoor2;
};

door3.onclick = () => {
  doorImage3.src = openDoor3;
};

randomChoreDoorGenerator();
1 Like

I now get a different error (using dev tools -> console):

TypeError: Math.Random is not a function

looking at the documentation:

something looks off, do you see it?

Yes sir, the R in random was capitalized.

Thanks a lot and also for leading me in the right direction without giving me what ended up being a simple resolutions.

2 Likes