6. List 'em all! Need help with the list function


#1



var friends = new Object();

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

friends.bill = new Object();
friends.bill.firstName = "Bill";
friends.bill.lastName = "Gates";
friends.bill.number = "555 - 255";
friends.bill.address = ["One Microsoft Way", "Redmond", "WA", "98052"];

friends.steve = new Object();
friends.steve.firstName = "Steve";
friends.steve.lastName = "Jobs";
friends.steve.number = "555 - 256";
friends.steve.address = ["One Milyway", "Apple Drive", "AA", "97464"];


Its saying that my code is correct but I don't understand how the list function is working (in other words I guessed until I got it right :joy: bad coding habit I know! ). But can someone try to please explain it to me in the simplest way possible? Thank you in advance :slight_smile:


#2

list function is not working.call the list function.like

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


#3

the function list is not working since its not been call but if you call it it will print twice since you re already printing it once with the console.log


#4

can you please give me your full code?


#5

I dont thinks thats allowed, but the only difference would be is that my:

var list = function(friends) {
.....code...
}

would be on the bottom.. ill use your code as an ex:

var friends = new Object();

friends.bill = new Object();
friends.bill.firstName = "Bill";
friends.bill.lastName = "Gates";
friends.bill.number = "555 - 255";
friends.bill.address = ["One Microsoft Way", "Redmond", "WA", "98052"];

friends.steve = new Object();
friends.steve.firstName = "Steve";
friends.steve.lastName = "Jobs";
friends.steve.number = "555 - 256";
friends.steve.address = ["One Milyway", "Apple Drive", "AA", "97464"];

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

like that


#6

There is no problem if you write the code like this :slight_smile: and you told me after calling the list function it'll print twice.but it shouldn't be.call the list function
you can use codecademy lab :slight_smile: