Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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 90,705 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.