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

Björn Wauben
Björn Wauben
10,748 Points

Adding properties to an Object

The challenge is: "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'."

My code keeps bringing up a syntaxError. I can't see what's wrong. Are these al numbers? I thought the second and third one are supposed to be strings? Seems really silly I can't pass a challenge where I just need to type three properties in an Object.

script.js
var paris {
    population = 2.211e6,
    latitude = '48.8567 N',
    longitude = '2.3508 E'          
};
index.html
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JavaScript Objects</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>
Björn Wauben
Björn Wauben
10,748 Points

I found the problem on my own. Somehow in the editor of the challenge my properties turned "blue" instead of "green" inside the object. I copied a similar Object from a later challenge and edited the numbers to pass this particular challenge. Now it passed. Strange.

10 Answers

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,253 Points

Hi there Bjorn,

You can also try

var paris {
    population:  2.211e6,
    latitude: 48.8567 N,
    longitude: 2.3508 E          
};

The 2 main things I noticed were that Object properties are part of a structure of keys and associated values.

Also number values are not enclosed in quotes. :-)

Try this and it should pass too.

Hello Jonathan,

I tried your code above, it says:

SyntaxError: Parse Error

Any ideas?

EDIT:

I passed the challenge by entering this code:

var paris = {
    population = 2.211e6,
    latitude = '48.8567 N',
    longitude = '2.3508 E'          
};
Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,253 Points

It must be due to the N and the E in the code, which I didn't pick up on. Ooops!

I but if this is an object, I can't see why assigning them with = works. An object is a structure of keys and the values.

This code will pass

var paris = {
 population:  2.211e6,
    latitude: '48.8567 N',
    longitude:'2.3508 E' 

};

but this won't.

var paris = {
 population:  2.211e6,
    latitude: '48.8567 N',
    longitude:'2.3508 E' 

};

The challenge wouldn't accept N or E from me. It worked after I wrote the code that you have, but without the N and E.

this passed for me,,

var paris = { population: 2.211e6, latitude: 48.8567, longitude: 2.3508

};

Michael Oxborrow
Michael Oxborrow
7,186 Points

I think there is a bug in this question. Same thing happened to me. Correct code not passing.

Miriam Rozenbaum
Miriam Rozenbaum
3,671 Points

They do not want you to use the 2.211e6. (Maybe its there to just confuse) Use the other number provided for the population. (that's 2.211 million using exponential notation)

var paris = { population : 2.211, latitude : '48.8567 N', longitude : '2.3508 E'

};

This work for me.

var paris = { population: 2.211e6, latitude:'48.8567 N', longitude: '2.3508 E' };

This code worked for me

var paris = { population: 2.211e6, latitude:'48.8567 N', longitude: '2.3508 E' };

Douglas Christman
Douglas Christman
10,045 Points

Same here. I kept getting an error that it couldn't find the properties population, longitude and latitude, even though they were clearly defined. I had to reset the code several times for it to work.

var paris = { population : “2.211e6”, latitude : “48.8567 N”, longitude : “2.3508 E” };

It's pretty important to put quotation marks around the strings.

Why does the code must take quotation marks ' ' for the last two properties? I know they are coordinates but why?

var paris = { population: 2.211e6, latitude: '48.8567 N', longitude: '2.3508 E'

};