List all the properties!


#1


https://www.codecademy.com/en/courses/objects-ii/1/5?curriculum_id=506324b3a7dffd00020bf661#


Oops, try again. It looks like you didn't print the value of nyc's fullNameproperty.


var nyc = {
    fullName: "New York City",
    mayor: "Bill de Blasio",
    population: 8000000,
    boroughs: 5
};

// write a for-in loop to print the value of nyc's properties
for(var i in nyc)
{
    console.log(nyc.i);   //Why this is not working, this is same as nyc.fullName and so on, for each particular iteration 
    console.log(nyc[i]);   //why this works?, this is same as nyc[fullName] which is wrong it should be nyc["fullName"]
}


#2

Because you are wanting to print the value of each property in nyc. To do this you need to use bracket notation not dot notation. Remove this part from your code.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.