Lesson 6 Contact list


#1

Her is my code. I keep getting an error message telling me that I have not created a function called "list". But i have and I cant for the life of me figure this out. Please help me!!!
var friends = {};
friends.bill = {
firstName: "Bill",
lastName: "Bonkerz",
number: "(555) 555-5555",
address: ['One Microsoft Way','Redmond','WA','98052']
};
friends.steve = {
firstName: 'Steve',
lastName: 'Stevenson',
number: '(555) 555-5555',
address: ['One Microsoft Way','Redmond','WA','98052']
};
var list = function(friends) {
for (var firstName in friends) {
console.log(friends);
}
};


#2

should be

var list = function(friends) {
            //you begin iteration over your friends lists
            for (var firstName in friends) {
                //you dont want to print the list each time
                //but rather each friend in the list
                //hence you want to print 'firstName'
                
                
                //***Note*** the 'friends' and 'firstName' variables
                //here have nothing to do with the one that has been 
                //defined before this block
                //they are local to the function only
                console.log(firstName);
            }
        };

#3

Are you sure? If my object is called 'friends' I can put any argument in the 'list' function but in the for/in loop I need to to write for ( var firstName in friends) otherwhise I don't get what I need. Furthermore I've noticed that if I give to the 'list' function and to the for/in loop ( i mean : var list = function(otherName) { for (var firstName in otherName)..... } a different name from the Object 'friends' still works.... why?