Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Introducing JavaScript Finishing the Game Adding Animated Characters

Alexandra Velez
Alexandra Velez
Front End Web Development Techdegree Student 9,313 Points

How to identify JavaScript game items in code?

Video Screenshot http://somup.com/cYhXb8joMZ

Is there a best practice for labeling game elements in the code?

Right now, they share so many variables in common it's tricky to separate game components.

1 Answer

Steven Parker
Steven Parker
228,039 Points

This game is a bit unusual in that the objects don't have individual identifiers other than the name of the image. The other factor is just the x and y coordinates where they are placed. There is no unique identifier, but as the game reacts to any object of the same type identically, there doesn't need to be.

In games where the objects do need to be uniquely identified, I'd expect to see identifiers with descriptive names more like what you are suggesting. The only "best practice" I can imagine applied to such names would be that the name reflect something identifiable about the object and be unambiguous.