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 trialMatt Bloomer
10,608 Pointsarrays and objects
Why isn't what I have working?
var objects= [{
var objects = [ {question: "one + two", answer: "three" }
{question: "two + two", answer: "four"}
{question: "three + two", answer: "five"}
];
];
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JavaScript Objects</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>
4 Answers
Marcus Parsons
15,719 PointsHi Matt,
It looks like you have two sets of var objects
when you only want one. You have the syntax almost correct inside of the array, except that each object has to be separated by a comma except for the very last object.
var objects = [
//comma inserted after this object
{question: "one + two", answer: "three" },
//comma inserted after this object
{question: "two + two", answer: "four"},
//no comma here because it is last object
{question: "three + two", answer: "five"}
];
Matt Bloomer
10,608 PointsI don't understand the answer.
Marcus Parsons
15,719 PointsYou start off with an empty array literal and create the variable objects
which is equal to that empty array literal which is []. Next, you put those 3 objects into the array. Each object is surrounded by curly braces {}. Each object has to be separated from the object before it, so you need a comma after the ending of each object.
Matt Bloomer
10,608 PointsI think I tried that, and it didn't work.
Marcus Parsons
15,719 PointsIt does work 100%. You must copy and paste correctly.
Matt Bloomer
10,608 PointsWhatever...I will just get help from someone else at another time.
Marcus Parsons
15,719 PointsI gave you the correct explanation and correct answer. If you copy and paste the code I gave you (which explains what I did), you'll see that the challenge passes. That is a poor attitude to have to someone who's trying to help you.