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

Array of objects

I am trying to create an array with objects inside of it. I tried the code below and it's giving me a parse error... stack overflow is suggesting I use the array.push() method but this is the example I was given in Treehouse for how to initialize them together. Any suggestions?

var objects =[ { letter: 'a';, number: 1; }, { letter: 'b';, number: 2; }, { letter: 'c';, number: 3; }

];

script.js
var objects =[
  { 
    letter: 'a';,
    number: 1;
  },
  {
    letter: 'b';,
    number: 2;
  },
  {
    letter: 'c';,
    number: 3;
  }

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

Steven Parker
Steven Parker
229,732 Points

The error is caused by the semicolon characters inside the objects, which are not part of object syntax.

Remove the semicolons (except for the one at the end of the assignment) and you will pass the challenge.

AHH! Thank you so much, It's always something simple! haha