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 Access and Set Object Properties

Add a new property -- country -- to newYork. Don't change the original object, just add this new property using a = sign

Iam having difficulty passing this task

script.js
var newYork = country {
  population: 100, 
  population: 8.406e6,
  latitude: '40.7127 N',
  longitude: '74.0059 W',
  country: USA



};
index.html
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JavaScript Objects</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>

3 Answers

hello. remember the way to add keys and values to objetcs

object.keyName = value;

// in this case newYork is the object, 

population: 100, 
// polutation   is the key
// 100   is the value

how would you add another key and value to this object?

newYork.key = 'value';

i hope this makes senses

Steven Parker
Steven Parker
231,269 Points

It looks like you're on task 2, but the first task was "Add a line of code that sets the population property to 8.406e6. Don't change the original declaration of the object."

Remember the warning in the instructions: "Important: In each task of this code challenge, the code you write should be added to the code from the previous task.", so the code you added to pass task 1 should be left as is when you work on task 2.

Then for task 2, it says: "Don't change the original object..." but the code above shows "country" added to the original object. Instead, write a line of code to add it using an assgnment as the instructions asked: "just add this new property using a = sign".

this is how the code from task 1 looks like and it let me pass: var newYork = { population: 100, population: 8.406e6, latitude: '40.7127 N', longitude: '74.0059 W'

}; however now, I still dont get how should I enter the country

Steven Parker
Steven Parker
231,269 Points

I guess the checker wasn't being very thorough. Remember the instructions say "Don't change the original declaration of the object."

Both the new population and the country should be added after the object using assigments ("=").