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

Jordan Green
Jordan Green
6,363 Points

When I fill the array literal with object literals the arrays no longer pass the first test. What's wrong here?

I used the following code to pass the second part of this question only to be confronted with the problem that the object literals do not cause the array literal not to pass. The instructions say that I should put the objects inside of the array. What am I missing? Is my code off? Am I not formatting the objects correctly? Any insight would be greatly appreciated.

var objects = [ var object1 = {love: 50, loss: 25}, var object2 = {health: "Nope", health2: 34}, var object3 = {demon: [12, 14, 13, 2], demongate: venus}, ];

Thanks

script.js
var objects = [ 

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

5 Answers

Seth Kroger
Seth Kroger
56,413 Points

You don't need the "var objectn =" part inside the array brackets, and you have an extra comma after the last object. Also in the last object you have "demongate: venus" that will look for a variable named venus you haven't declared yet.

Jordan Green
Jordan Green
6,363 Points

Thanks Seth, I'll try these suggestions.

Hi,

the expected solution is like the below one. You have added an equal to sign which wont be required. And few syntax errors. Can you go through the video again and try the challenge again.

var objects = [ {ques:'aa',
                 ans:'bb'} , 
               {ques:'cc',
                ans:'dd'} , 
               {ques:'ee',
                ans:'ff'} ];
var objects = [
  {
    "firstName":"John",
    "lastName":"Doe"
  },
  {
    "age":24,
    "sex":"M"
  },
  {
    "petName":"Fido",
    "school":"Treehouse"
  }
];

ur welcome bro