Why is my list function printing twice in the Contact List exercise?


#1

I was able to move on in this exercise, I am just curious why my output is:
bill
steve
bill
steve

I'm not sure why it prints the entire list twice over, any ideas? Thanks!


var friends = new Object();

var friends = {
    bill: {
        firstName: "Bill",
        lastName: "Whillup",
        number: "314-455-2322",
        address: ["One Sunset Blvd"]
    },
    steve: {
        firstName: "Steve",
        lastName: "Jordan",
        number: "808-332-4443",
        address: ["One Vegas Court"]
    }
};    

var list =  function (friends) {
    for (var firstName in friends) {
      console.log(firstName);
}
};

list(friends);


#2

@lisa.jordie,

In some sections of this course, the course-checker Display's data
this you could then identify by placing two EXTRA code-line's:
console.log( "== My End ==" );
console.log( "== All that is displayed now, is the course-checker ==" );

Thus use

list(friends);
console.log( "== My End ==" );
console.log( "== All that is displayed now, is the course-checker ==" );

#3

@leonhard.wettengmx.n Thank you!!


#4

It is not necessary to call the function in the end. You already tell the console to print the names. And when you call the function you're printing the names again. Try removing the last bit where you call the function:

list(friends);

and see if it works.

I also noticed that on the very top you've created the object friends twice. 1 - Constructor 2 - Literal way.