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

Igor Harasimluk
Igor Harasimluk
2,907 Points

Each object should have 2 property/value pairs.

what's wrong??

script.js
var objects = [
  {age: 35, false},
  {name: "bibmo", age: 19 },
   {name: "dingo", answer: 19 }
];
index.html
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JavaScript Objects</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>

2 Answers

Hi,

If the question is: make more than one object and make sure each object has two properties and values.

Syntax: ' var object = { ... } ; ' --> Curley {} not []  and separate properties with a comma ,

var obj1 = {                          //open the braces {
               propA:  valueA,      
               propB:  valueB 
                  };                       //close the braces };

var obj2 = { 
              propX:  valueX,        
              propZ:  valueZ 
                  };  

After a while this will be common knowledge. I personally like to keep my brace-opens and -ends on different lines, this way I can clearly visualise what is in my object, function or class.

TIP: when you get stuck your auto-reaction should be to google: 'object javascript'. You will find many sites that will tell you how something is written or what it does or can do.

Hope this helps,
Cc

Igor Harasimluk
Igor Harasimluk
2,907 Points

Thanks Chloe for the help and fast respond!

Igor