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

What am I doing wrong here? JS Challenge

I'm not sure what I am doing wrong here. I obviously am not sure as to what is being asked. Please help.

script.js
var objects = [

  var student = {
      firstName: "daniel",
      lastName: "flynn",
      middle: "j";

}

  var grades = {
      homeWork: [93],
      tests: [97],
      quizScores: [98]; 

}

  var address = {
      city: "Sheridan",
      county: "Yanhill",
      street: "Bridge";
}

];
index.html
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JavaScript Objects</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>
Emma Walker
Emma Walker
1,390 Points
var students = [ 
{
      firstName : "daniel",
      lastName : "flynn",
      grade : "A"
},
{
      firstName : "John",
      lastName : "Doe",
      grade : "B"
},
{
      firstName : "Sam",
      lastName : "Smith",
      grade : "C"
}
];

The idea is to have an array of student objects, each is a different student but each has the same information about each student: their first name, last name and grade, for example. They shouldn't be variables. You also need commas between the different array objects.

1 Answer

andren
andren
28,558 Points

You seem to understand the gist of the task, but there are some fundamental issues with your code:

  1. Arrays cannot store variable declarations. Arrays are just a list of values separated by a comma.
  2. Putting a semicolon after the last property of an object is invalid. No special symbol is needed after the last property.
  3. The challenge asks for each object to have two properties, you have given them three.

If you remove all of the variable declarations, remove the semicolons and remove the third property of each object. Like this:

var objects = [
  {
      firstName: "daniel",
      lastName: "flynn"
  },
  {
      homeWork: [93],
      tests: [97]
  },
  {
      city: "Sheridan",
      county: "Yanhill"
  }
];

Then your code will pass the challenge.