Chore Door Help Request

Hello and good afternoon on this beautiful Monday,

I am currently working on the Javascript project Chore door. I’ve progressed relatively well on this project just doing it on my own but I’ve hit a snag right up around step 45. I moved through to 48 and surfed the forums only to realize the problem I’ve been encountering wasn’t related to a browser error or attributed to bad connection.

I’ve seen others post about their doors disappearing, and I have that problem every other time the page is refreshed.

I’ve added the entirety of my code below and could use a fresh set of eyes to find the error.

I’ve also used the developer tools that was recommended on another thread and each time the error runs it is telling me that the object at said location is undefined. But when it does work the images are registered into the log.

// global variables const doorImage1 = document.getElementById("door1"); const doorImage2 = document.getElementById("door2"); const doorImage3 = document.getElementById("door3"); 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 = spaceDoorPath; openDoor3 = beachDoorPath; } else { openDoor3 = BotDoorPath; openDoor1 = beachDoorPath; openDoor2 = spaceDoorPath; }; }; const numClosedDoors = 3; let openDoor1; let openDoor2; let openDoor3; function playDoor() { numClosedDoors--; if (numClosedDoors === 0) { gameOver(); } else { numClosedDoors--; }; } // door paths const botDoorPath = ""; const beachDoorPath = ""; const spaceDoorPath = ""; // door clicking doorImage1.onclick = () => doorImage1.src = openDoor1; doorImage2.onclick = () => doorImage2.src = openDoor2; doorImage3.onclick = () => doorImage3.src = openDoor3; console.log(randomChoreDoorGenerator());

Thanks in advance to anyone who can take a look at this! I am in your debt.

Line 16 jumps out, possible typo.

Yup! amazing how I scanned that area so many times and still missed it. Teamwork makes the dream work!


This is going to stray way off topic, and I apologize in advance, but I think your example demonstrates something interesting about how the human brain reads written words. It turns out, it doesn’t read each letter; instead it looks at the overall shape of the word and your brain fills in the meaning. This allows us to skim across words in a paragraph quickly, which is an incredible example of human intelligence, but unfortunately it’s also easy to fool, and this is why our code often trips up over simple typos.

For those interested, the issue of typeface and legibility in road signage is explored in this article. I believe it was British designers who first adopted the use of lowercase letters in their road signage, after recognising that the human brain could process words written in lowercase lettering faster (and at greater distance) than uppercase, which meant less time spent staring at a sign, and more time on the road.

1 Like