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 Add Properties to an Object

Raeed Sabree
Raeed Sabree
10,664 Points

How to create an object

script.js
var paris = {};
index.html
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JavaScript Objects</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>
Tommy Gebru
Tommy Gebru
30,164 Points

the trick here is in the instruction of the three values one of them is without quotation marks " " because it is a number value :smile:

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'.

3 Answers

Raeed Sabree
Raeed Sabree
10,664 Points

that helps a ton thank you so much

Tommy Gebru
Tommy Gebru
30,164 Points

Example 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
Raeed Sabree
10,664 Points

can you show me what it looks like?

Raeed Sabree
Raeed Sabree
10,664 Points

so why does it keep saying this stuff about longitude and latitude for?

Tommy Gebru
Tommy Gebru
30,164 Points

What is your input and/or error message?

Raeed Sabree
Raeed Sabree
10,664 Points

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'.

Tommy Gebru
Tommy Gebru
30,164 Points

Were 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! :smile:

Raeed Sabree
Raeed Sabree
10,664 Points

okay so how would i put these numbers in an object ?

Raeed Sabree
Raeed Sabree
10,664 Points

they want me to use population, longitude and latitude can you show me how to do that using them?

Tommy Gebru
Tommy Gebru
30,164 Points

Similar 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'};