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 trial

JavaScript JavaScript Loops, Arrays and Objects Tracking Data Using Objects Review Object Basics

Leroy Klotz
Leroy Klotz
2,814 Points

Correct answer is not even listed?

var animal = { name : "Zebra", lifeSpan: 25, weight: 770 };

Which of the following code examples would change the weight property of the animal object?

A
weight = 770;
B
zebra.weight = 770;
C
animal['weight'] = 770;

For the question above, the answer (according to the video) should be as follows: animal.weight = ...

However, as you can see, it´s not even listed. After taking the quiz 2 times I now know that the correct answer (according to the quiz) is answer C, however this isn´t representative of what is explained in the video whatsoever. I´m well confused at this point. Any comment?

1 Answer

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,252 Points

I believe what's happening here is that the quiz is trying to reinforce that there is more than one way to set or change the value of a property of an object.

These ways are known as dot and bracket notation.

Dot is the way you've identified. where you set object.property. But with Bracket notation, you use object["property"] or object["property"] = value

Leroy Klotz
Leroy Klotz
2,814 Points

Thank you Jonathan for your clarification.