Avatar of MP techtrek
MP techtrek
 asked on

Can you reference an object with a variable name?

If a variable contains a string that is the same as the name of an object. Can you use that variable in place of the object name?

https://cit111byui.github.io/object.html

Line 58 inside of the showInfo function:

carInfo.textContent = carSelected.getInfo();

Does not work as it is referencing the variable carSelect, but if I replace it with car0 or any of the objects it works fine. But the idea is to show the info of the car that is clicked on.

How can I get this to work?
HTMLJavaScript

Avatar of undefined
Last Comment
MP techtrek

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
leakim971

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
MP techtrek

ASKER
Awesome, thanks leakim971
Your help has saved me hundreds of hours of internet surfing.
fblack61