7. Search for a friend ... not returning contact info


#1



https://www.codecademy.com/courses/javascript-beginner-en-3bmfN/0/7?curriculum_id=506324b3a7dffd00020bf661#


Oops, try again. It looks like your search function doesn't return contact information for Steve.


var search = function(name){
    for (var key in friends){
        if (friends[key].firstName === name) {
            console.log(friends[key]);
            return friends[key];
            }
            else if (
                friends[key].firstName != name){
                console.log("the name cannot be found.")
                }
    }
};

search("Bill");
search("Steve");
search("Joe");


#2

Your function seems ok, can you paste your friends variable?

I think you should use console.log("the name cannot be found.") after for loop. It will log this message only if there's no friend with firstName === name. Now it's printing to console for every friend which firstName != name.