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

Objects, Inside An Array Challenge - Why?

js
var objects = [
  var obj1 = {
    name: "matt",
    age: 25
  },
  var obj2 = {
    name: "fareed",
    age: 20
   },
  var obj3 = {
    name: "melinda",
    age: 21
   }
];

Error: "Looks like step one, is no longer working." Step one: was simple to creat an array literal with nothing in it (named to objects). But, when I attempt to put my 3 objects (with two property/value pairs each) inside the array... it wont work. Help please?

script.js

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

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,858 Points

Hey there,

You're on the right track, except you don't assign variable names to the object in a key: value pair. Other than that you're syntax is correct.

var objects = [
  {
    name: "matt",
    age: 25
  },
  {
    name: "fareed",
    age: 20
  },
  {
    name: "melinda",
    age: 21
  }
];

Keep Coding! :dizzy:

Thanks Jason so, it essentially comes down to a syntax error?

Jason Anders
Jason Anders
Treehouse Moderator 145,858 Points

Yep.

The "Task one is no longer passing" is very misleading. It will always be something done in the current Task and never actually related to the first task. So, when you encounter this, don't click "Go back to task one." Just look carefully at your code (specifically any code changed and / or added since the last Task) for any syntax errors. Often it's as simple as a missing semi-colon. I've been in a challenge and on Task 3 or 4... missed a semi-colon and got the "Task one" error.

:)

Tushar Singh
PLUS
Tushar Singh
Courses Plus Student 8,692 Points

It's a very minor mistake. Why are you creating variables "var" inside an array.

array =[1, 2, 3] that's it no var.

var objects = [
   obj1 = {
    name: "matt",
    age: 25
  },
 obj2 = {
    name: "fareed",
    age: 20
   },
  obj3 = {
    name: "melinda",
    age: 21
   }
];

Thanks for your answer Tushar!

Tushar Singh
Tushar Singh
Courses Plus Student 8,692 Points

Anytime, I did the same mistake when I was working on this challenge :wink:

Tyler Durden
Tyler Durden
2,406 Points

I was getting a parse error until I named my array "var objects". That's kind of dumb because it was never explicitly stated to call the array that, although it was hinted imo.