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 trialRaeed Sabree
10,664 PointsHow to create an object
var paris = {};
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JavaScript Objects</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>
3 Answers
Tommy Gebru
30,164 PointsHope that helps
Raeed Sabree
10,664 Pointsthat helps a ton thank you so much
Tommy Gebru
30,164 PointsExample object:
var person = {firstName:"John", lastName:"Doe", age:50, eyeColor:"blue"};
You need to create a property & value pairing, it will be done three times for this challenge, within the paris object... similarly for the person object I have created four pairings. Each person & associated value describes the object
Raeed Sabree
10,664 Pointscan you show me what it looks like?
Raeed Sabree
10,664 Pointsso why does it keep saying this stuff about longitude and latitude for?
Tommy Gebru
30,164 PointsWhat is your input and/or error message?
Raeed Sabree
10,664 PointsAdd three properties to this object: population with a value of 2.211e6 (that's 2.211 million using exponential notation), a latitude property with a value of '48.8567 N', and a longitude property with a value of '2.3508 E'.
Tommy Gebru
30,164 PointsWere you able to pass the challenge?
Here is another example of an object:
var car = {type:"Fiat", model: 500, color:"white"};
notice that the model property has an associated value of 500, which is not within quotations because it is a numeric value...... the other values within the object car however are strings....
Therefore from the instructions for the challenge we see that the object's property called population has a value of 2.211e6 (that's 2.211 million using exponential notation)... which is a number, not a string....
Yet for latitude and longitude we can see that they are strings with numbers letters and even spaces!
Raeed Sabree
10,664 Pointsokay so how would i put these numbers in an object ?
Raeed Sabree
10,664 Pointsthey want me to use population, longitude and latitude can you show me how to do that using them?
Tommy Gebru
30,164 PointsSimilar to the examples we begin like so:
var paris = {};
this would be our empty object called paris....
paris is similary to an array... it contains & lists data.. data in an object has a format...
var paris = {propertyName:valueName};
we then assign the property & name pairings
var paris = {population: 2.211e6}; //the value here is shorthand for really long number!
so the completed challenge should be
var paris = {population: 2.211e6, latitude: '48.8567 N', longitude: '2.3508 E'};
Tommy Gebru
30,164 PointsTommy Gebru
30,164 Pointsthe trick here is in the instruction of the three values one of them is without quotation marks " " because it is a number value
Add three properties to this object: population with a value of 2.211e6 (that's 2.211 million using exponential notation), a latitude property with a value of '48.8567 N', and a longitude property with a value of '2.3508 E'.