9/30 -- Code runs, but I don't think my code is right


#1

This is my code:

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

for (var fullName in nyc) {
console.log(fullName);
};

Could someone explain me what I missed or what am I wrong. Thanks


#2

Perhaps you wanted something like this

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

for (var fullName in nyc) {
    console.log(fullName + ": "+ nyc[fullName]);
}

#3

I've tried your code, it print all the data of nyc but it gives me error: "
Oops, try again. It looks like you didn't print nyc's fullName".

I just think what thing should I put on the console.


#4

I can't see anything wrong with your code. All they want you to do in this lesson is to print all of the property's name to the console which are fullName, mayor, population and boroughs.

In the next lesson, they will teach you how to print out all the values of the property which are new york city, bill, 8000000 and 5, etc


#5

try this

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

for (var name in nyc) {
    console.log(name);
}

#6

@steve80

Oh! I got it. I'm just focusing on printing the values, and the instruction want to print the property only.

Thanks buddy!


#7

@rydan

Thanks also pal for the help.


#8

By the way, the next activity after that one is about printing out the names associated with the properties. You're probably past this, but this exercise was just for the purpose of showing the property names in NYC.


#9

thank you rydan for the code