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 Create an Array of Objects

How to add objects to an Array?

I had to create an array literal. Inside the array literal, I must add three object literals or three object values. The three values should have two property values. I received this message when I submitted my answer. Bummer! There should be three items in the array.

What am I doing wrong, or am I missing something?

script.js
var objects = [

name = 'Sally',
age = '35',
Occupation = 'Actress',

name = 'Horton',
age = '60',
Occupation = 'President',

name = 'Gertrude',
age = '15',
Occupation = 'Student',

];
index.html
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JavaScript Objects</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>

1 Answer

rydavim
rydavim
18,814 Points

Looks like your syntax is just a little bit wonky. You'll need to wrap your different array items in curly braces to group them. Additionally, I believe that challenge only wants two properties for each item so you'll probably need to eliminate one of your properties.

var objects = [
  // Don't forget the curly braces around your array items.
  { name: 'Sally',
    age: '35'
    // Occupation: 'Actress'  -- I commented this property out so there are only two.
  },
  { name: 'Horton',
    age: '60'
    // Occupation: 'President'
  },
  { name: 'Gertrude',
    age: '15'
    // Occupation: 'Student'
  }
];

That should do it though, looks like you've got the idea. Happy coding! :)

Thank you for your help. Seeing the corrections you made, makes the question to the challenge more understandable.