7.Search for a friend


#1

Hi getting an error of: "It looks like your search doesn't return contact information for Steve"

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

var search = function(name) {
for (var list in friends) {
if (name === friends.firstName) {
console.log(friends.firstName)
return friends
}
}
}

var friends = {
bill: {
firstName: "Bill",
lastName: "Gates",
number: "(206) 555-5555",
address: ['One Microsoft Way','Seattle','Washington']
},
steve: {
firstName: "Steve",
lastName: "Jobs",
number: "(315) 546-4342",
address: ['1 Infinite Loop','Cupertino','California']
}
};


#2

You have to call search function at the end to get the output in console. Also in your search function you haven't specified the array index to search for.

Your search function should be something like this

var search = function(name) {
    for (var list in friends) {
        if (name === friends[list].firstName) {
            return friends[list];
        }
    }
}
list(friends);
search('Steve');

#3

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