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! While you're at it, check out some resources Treehouse students have shared here.
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 trialMihai Childesco
9,326 Pointsi didnt understand that var prop = 'beer' ernie[prop] how did the var prop transfered in the object ernie ?
i didnt understand that
Steven Parker
231,269 Pointsjulian, try starting a fresh question, and be a bit more explicit about what you're having trouble with.
2 Answers
Christian van Lierop
13,758 PointsI understand your confusion. Let me tyry to explain:
- The property 'breed' is already declared in the object 'ernie'
- now you create a variable called 'prop' with a string value of 'breed'
- instead of calling the method as ernie['breed'] you can now also call it using ernie[prop] because the variable prop is equal to the string 'breed' (prop = 'breed')
Hope this clarifies it a bit.
Steven Parker
231,269 PointsDid you try out the examples yourself? A bit of experimentation might be much more valuable than additional explanations.
And the property in the example was "breed". We probably should not give ernie any "beer", he's only 1 year old!
Tsenko Aleksiev
3,819 PointsHaha liked that last one
julian Ellis
3,542 Pointsjulian Ellis
3,542 PointsI too am struggling with this