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 trialChuck C
3,957 PointsI think your code validation is wrong again. It works in the console but not in your code emulator
var objects = [];
var obj1 = { name: 'Ok', age: 19 } var obj2 = { name: 'Ok', age: 19 } var obj3 = { name: 'Ok', age: 19 } objects.push(obj1, obj2, obj3);
var objects = [];
var obj1 = {
name: 'Ok',
age: 19
}
var obj2 = {
name: 'Ok',
age: 19
}
var obj3 = {
name: 'Ok',
age: 19
}
objects.push(obj1, obj2, obj3);
<!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
231,269 PointsWas the validation wrong before?
Anyway, this time the instructions say "Inside the array literal, add three object literals.". The code shown here does add three objects, but not as object literals, and not done inside the array literal. It's first creating three variables and then dynamically pushing them onto the array.
When following the instructions, you will create only only variable (objects) and have only one statement.
When you try challenges outside the validator, always remember that the IDE has no idea what the actual objective is in the instructions.
Chuck C
3,957 PointsChuck C
3,957 PointsSorry but I don't get it.
Is this not considered an object literal ? var obj1 = { name: 'Ok', age: 19 }
You say "not as variable". Ok but that's not mentioned ?
So I should do this ? var objects = [{ name: 'Ok', age: 19 }, { name: 'Ok', age: 19 }, { name: 'Ok', age: 19 }];
Steven Parker
231,269 PointsSteven Parker
231,269 PointsYou got it exactly, 3 object literals inside an array literal. Good job!
In your example above, "
{ name: 'Ok', age: 19 }
" is an object literal, but it's not inside the array literal. And "obj1
" is a variable that gets added later by a "push" statement.