I'm ashamed I killed DRY



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) {
for (var mayor in nyc) {
for (var population in nyc) {
for (var boroughs in nyc) {


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){


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.


This is how I think it SHOULD work:


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


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


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