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 JavaScript Object Notation

H Yang
H Yang
2,066 Points

declaring objects

In the last challenge we were supposed to make an array of three objects; each object was to have 2 property: value pairs.

Initially I tried declaring each object:

var objects = [
  var David = {sex: "male", age: 32},
  var Gwen = {sex: "female", age: 28},
  var Henry = {sex: "male", age: 31}
];

It was deemed incorrect until I took out declaring each object. This was accepted as the right answer:

var objects = [
  David = {sex: "male", age: 32},
  Gwen = {sex: "female", age: 28},
  Henry = {sex: "male", age: 31}
];

When should we declare objects? Is it wrong to declare them in the middle of the list, or was this just the challenge looking for a particular answer?

Thank you.

1 Answer

Mike Henry
PLUS
Mike Henry
Courses Plus Student 5,373 Points

the only variable is "objects" and it is an array. The others are elements in the array that contain key value pairs.

H Yang
H Yang
2,066 Points

Thank you Mike Henry