Choredoor Project - Task #67 Confusion

So I have just finished the Choredoor project from Chapter 6 of the Web Dev path, Javascript Interactive Websites.
So, the startRound function asks us to initialize all variables back to their initial values, including the doorImage variables, doorImage1, doorImage2 etc set to closedDoorPath. When I do this and refresh the page, nothing happens and the doors stay ‘closed’ when I click. When I check the video tutorial she uses door1.src, door2.src, door3.src as the variables to initialize. Of course when I refresh the page it now works and I can open the doors… So I’m confused as to what door.src is. There is no declaration of these within the Global variables. What exactly is door.src? And why would doorImage(x).src not work? I see ‘door’ used as a parameter in the playDoor function, and ‘door1’, ‘door2’, ‘door3’ are selectors based on HTML ids, but that is different than a JS variable. What the heck? Where is door1.src, door2.src etc coming from and why do they work? I understand the logic of the program and how the subroutines fit together but this part baffles me.

const startRound = ()=> {

  door1.src = closedDoorPath;

  door2.src = closedDoorPath;

  door3.src = closedDoorPath;

  numClosedDoors = 3;

  startButton.innerHTML = 'Good Luck!';

  currentlyPlaying = true;

  randomChoreDoorGenerator();

}

Honestly, without seeing the full program you’re using, I’m not sure where these are coming from either or why they’re working.

It’s possible, in the video walkthrough, that they use door1.src because they initialised variables to represent each of the doors as door1 etc.

In your code, if you’re using the boilerplate which has the door objects pre-defined as const doorImage1 = document.getElementById('door1'); and so on then resetting them with doorImage1.src = closedDoorPath; should have worked.

It’s very difficult to say for sure why / what is not working in your overall program from only that small segment. :slight_smile:

Well now it works! Using doorImage1.src etc as initialized variables now works and I can click the doors open whereas before I could not. Not sure what went south the first time I tried those variables and still don’t know why door1.src, etc works as well. I’ll just leave it at that and happy that the program works as intended. Thanks for your help.

1 Like