I'm ashamed I killed DRY


#1



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

Guys I committed terrible crime here. I should get a chair for this one lol. This is the only way it granted me with "way to go". I get all properties printed out but all comes out 4 times. What's wrong besides the obvious ?


Replace this line with your code. 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 fullName in nyc) {
    console.log(nyc["fullName"]);
};
for (var mayor in nyc) {
    console.log(nyc["mayor"]);
};
for (var population in nyc) {
    console.log(nyc["population"]);
};
for (var boroughs in nyc) {
    console.log(nyc["boroughs"]);
};


#2

The for...in statement iterates over the properties of an object.

It is only necessary to make one for in statement

for(var x in nyc){
    console.log(nyc[x]);
}

#3

I know but that didn't work for me that's why I came up with this madness lol. I keep working on it. Gotta make it work.


#4

This is how I think it SHOULD work:


#5

I see you didnt try my code :slight_smile:

for (var fullName in nyc) {
    console.log(nyc["fullName"]); // remove the " "
};

Cause fullName is a propertie in your object and you log it four times on this way


#6

Nice ! Now it works nicely. Thanks mate. Kinda odd 'coz Codecademy teaches that bracket notation goes with quotes in a brackets.


#7

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