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

Stuck on code challenge - (might be a bug)

Question is:

"Inside the array literal, add three object literals. In other words, the objects array should have three values. Each object should have 2 property/value pairs."

Here is my code for task 2 of the challenge however it's not passing? is this a bug or have i made a mistake?

var objects = [ { name: 'John', age: 17
} { name: 'Rich', age: 21 } { name: 'James', age: 33 } ];

script.js
var objects = [
  {
    name: 'John',
    age: 17    
  }
  {
    name: 'Rich',
    age: 21
  }
  {
    name: 'James',
    age: 33
  }
];
index.html
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JavaScript Objects</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>

4 Answers

Colin Bell
Colin Bell
29,679 Points

You're forgetting the commas between your objects.

var objects = [
  {
    name: 'John',
    age: 17    
  }, // Here
  {
    name: 'Rich',
    age: 21
  }, // Here
  {
    name: 'James',
    age: 33
  } // Not here since it's the last one.
];

Ah okay - thanks Colin!

Hi guys! what is wrong with my code? what i'm doing wrong here? thank you much.

var objects = [ { question: 'How many states in the United States'?, answer: 50 }, { question: 'How many legs the spider has'?, answer: 6 }, { question: 'How many tires the car has'?, answer: 4 } ];

mazarul islam
mazarul islam
2,981 Points

has'? the ' is before question mark. should be after. for all your object literals question mark is after the string value

There is an "?" outside of the quotes: 'How many states in the United States'?,

Hope this helps

:)

when using this answer this is the error that I get Make sure you declare the objects array with the var keyword. and I know the var keyword is objects so I don't know whats wrong