List them all


#1



12. Contact List > List Them All


Search function does not work. I have compared it to the sample at the beginning of the course and my beginner programmer mind has not noticed any errors.


var friends = new Object();
friends.bill = {
    firstName: 'Bill',
    lastName: 'Gates',
    number: "(206) 555 - 5555",
    address: ['One Microsoft Way', 'Redmond', 'WA', '98052']
    };
friends.steve = {
    firstName: "Steve",
    lastName: "Jobs",
    number: "(408) 555 - 5555",
    address: ['1 Infinite Loop','Cupertino','CA','95014']
    };
friends.penis = {
    firstName: "Richard",
    lastName: "Cranium",
    number: "(718) 867 - 5309",
    address: ['420 fartface ave', 'Brooklyn', 'NY', '11234']
    };

var list = function(ls) {
    for(var key in friends) {
        console.log(key)
    }
};
var search = function(look) {
    for(var key in friends) {
        if(friends[key].firstName === name) {
            console.log(friends[key]);
            return friends[key];
        }
    }
};

list(friends);
search("Steve");


#2

this line:

if(friends[key].firstName === name)

you compare the firsts names in the objects with the name you pass as parameter on the function call, except when you created the function:

var search = function(look)

you didn't call the argument name, you called it look. Change look into name, or name into look, whatever.