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?

weight = 770;
zebra.weight = 770;
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
Jonathan Grieve
Treehouse Moderator 85,423 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 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.