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

Why is it not recognizing the second property?

I can't find the problem in my code to why the text editor doesn't recognize "age" as a property.

script.js
var objects = [
  {
    name = "Rapha",
    age = 29
  }
  {
    name = "Rosana",
    age = 28
  }
]
index.html
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JavaScript Objects</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>

3 Answers

You're forgetting the commas between your objects. Also you need to change equals to ':' this should do it :)

var objects = [ {

name: 'Charlie',
age: 17    

}, // Here

{

name: 'Ben',
age: 21

}, // Here

{ name: 'James', age: 33

} // Not here since it's the last one.

];

Hi there ?,

  • JS object literal is a comma-separated list of name-value pairs with colons (:), not equals sign (=).
  • You need to separate the items inside the array with commas (,).
  • You need to create 3 objects inside the array, not only two.

Have a good luck!
? Yuval ?

Hi Yuval! Thanks for the heads-up with the (:) in place of (=) Now I have a new issue. The third object isn't being recognized. My code is like this:

var objects = [ { name: "Rapha", age: 29, } { name: "Rosana", age: 28 } { name: "Greta", age: 4 } ]

Just found the issue! Thanks!!

I'm glad I could help. ?

Have a nice day! ?