Hi!
I’m working through the following project and the doors are always in the following order:
- Beach door, Space Door, Chorebot Door
Although I’m at the point in the exercise, #45, where it should be appearing in a random location each time.
Here’s the code, with a link removed because the forum won’t let me paste so many links. Would love any ideas. Thank you!
let doorImage1 = document.getElementById("door1");
let doorImage2 = document.getElementById("door2");
let doorImage3 = document.getElementById("door3");
let botDoorPath = //link removed per forum requirements
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 openDoor1
let openDoor2
let openDoor3
let numClosedDoors = 3;
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;
}
doorImage1.onclick = () => {
doorImage1.src = openDoor1;
}
doorImage2.onclick = () => {
doorImage2.src = openDoor2;
}
doorImage3.onclick = () => {
doorImage3.src = openDoor3;
}
randomChoreDoorGenerator()