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

Benjamin Guyton
Benjamin Guyton
6,858 Points

task 1 is no longer passing

I'm not sure where my error is in this code, the objective seems pretty straight forward, and everything I do leads to task 1 not passing

script.js
var objects = [
  var student = {

  },
  var teacher = {

  },
  var branch = {

  }
];
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

Valeshan Naidoo
Valeshan Naidoo
27,008 Points

So the array has to have 3 object literals within it, and each of the object literals must have 2 key-value pairs. You have the array, but with the object literals, you've declared each one. You don't need to do that.

var objects = [{},{},{}];

So the above is an array with 3 empty object literals. I don't need to declare them. Now I can add the key-value pairs inside each of them.

var objects = [{name: "sally", age: 32},
               {name: "bob", age: 22},
               {name: "tim", age: 29}
              ]