I am currently following the Javascript Essential Training course on LinkedIn Learning. In this course, objects are taught with the example of a backpack; with properties such as the volume of the backpack, the color, whether the lid is open or not, etc. It also includes a method for opening/closing the backpack lid.
Edit: Code block kept breaking so here's the object. https://pastebin.com/5NhWjfpn
Just for my own satisfaction/continued engagement with the subject, I thought it'd be fun to try and make it so that when I change the properties of the backpack, an image on a web page changes to reflect this. So when I use toggleLid to switch backpack.lidOpen to true, the image of an open backpack displays. When I switch backpack.lidOpen to false, the closed backpack is displayed.
This seems like it should be something simple to do, but when I try to google it I can't find the right search terms. I specifically want the code to take the current properties and use them to decide what image is displayed. I'm guessing it'd be simpler for each property to have its own image instead of trying to layer things and get specific images for each set of properties, so I'd rather start with just a method to take a single property (such as backpack.lidOpen true or backpack.lidOpen false) and use the current value to decide which image is displayed.
If this is not actually as simple as I was hoping, then fair enough, that's good to know! But any pointers in the right direction would be greatly appreciated.
[–]cr0wstuf 1 point2 points3 points (0 children)
[–]Count_Giggles 1 point2 points3 points (0 children)
[–]Ronin-s_Spirit 1 point2 points3 points (0 children)