7. Search for a friend | Error


#1

Hi people, I keep getting this error, what am I doing wrong??
Oops, try again. Did you create a function called search?

var friends = {
    bill: {firstName: 'Bill', lastName: 'Gates', number: '(206) 555-5555', address: ["Redmond"]},
    steve: {firstName: 'Steve', lastName: 'Jobs', number: '(420)-222-3333', address: ["Cuppertino"]},
};

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

var search = function (friends){
    for(var key in friends){
        if(friends[key] === firstName){
            console.log(friends[key]);
            return friends[key];
        } else {
            return 'Name could not be found...';
        }
    }
};


#2

@geekz45679

A return within the function
will cause an exit....

you would never find 'Steve' !!!

You will have to throw out

return friends[key];
    } else {
        return 'Name could not be found...';

#3

A post was split to a new topic: Looks like your search function doesn't return contact information


#4

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