True, but after that you are not calling doorImage1 anywhere in your code ;). Instead you are using the ids from the HTML and not the doorImage1, 2 and 3.
Btw your image location is wrong. The images are not stored in the same folder where the code is. Instead it is stored outside of the codecademy website.
Also, the paths are different from the instructions. I’ve saved the images locally and the code is running locally instead of on Code Academy . There’s nothing wrong with the image paths in the code.
Right, so for some reason my code does work in the Code Academy editor, but not locally.
Edit: Modifying the image paths to the Code Academy S3 bucket solves my issue locally, so the problem lies with the relative paths somewhere. I’m curious to find out what it is exactly. If I ever do, I’ll post it here
Isn’t doorImageN a global variable as well? It’s declared in the global scope, no?
Even after taking your advice on the paths, the doors just don’t open when using local paths.
Could you please elaborate as to why this would be “moot” ?
Yes it is declared in global scope, in this example, but it is less likely some other code will collide with them because they are not in the HTML as id. Given we declare them as constants, they cannot collide with anythng.
Do you have the images stored in the img folder?
The variable you are assigning img/ to is longer than the actual path name. Simpler just to use it and not take up memory with a superfluous variable.
Thank you for your valuable input Sir, I now understand what you were pointing out regarding my first point on global scope.
As pointed out in my previous posts, the doors open fine, the images change when I don’t use the if block in the .onclick functions. As soon as the if block is there, it doesn’t work anymore.
I understand this is probably out of scope for Code Academy (since I’m trying this locally), but it does intrigue me why it’s not working.
As for your last point, I actually followed your advice in another post, basically saying DRY:
let someImage = "path/to/image.jpg";
let someImage2 = "path/to/image2.jpg";
should better be:
let imagePath = "path/to/";
let someImage = imagePath + "image.jpg";
let someImage2 = imagePath + "image2.jpg";
That did look familiar… It would apply more to the long URLs in the track version. If the URL is a local path, then I would go with whatever is shortest, and not use a variable (which uses memory) if I didn’t have to. It’s not a deal breaker and it does help readability, to a certain degree.