Search for a friend?


#1

Where is the error here?

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

bill: {
    firstName: "Bill",
    lastName: "Gates",
    number: "(206) 555-5555",
    address: ["baanbrugsteeg", "Amsterdam", "1g"]
    },        
steve: {        
    firstName: "Steve",
    lastName: "Jobs",
    number: "(204) 535-5553",
    address: ["cantianstrasse", "berlin"]

    }
};

list(friends);

search("Steve")

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

however; console prints
bill
steve
"S"


#2

Try adding a { at the end of that.


#3

Helped a little bit; now the error is:

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

And the console prints:
bill
steve


#6

add a semi colon after search("steve")


#8

Perhpaps you've solved this issue already but I'll help anyway :slight_smile:

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

So after fixing the braces around your if statement You have to realize how your function is working. You are expexting 'friends', the parameter, to be an object to search. But in your code you are passing in a string. So it will never work like that. You should change the parameter being passed in to 'name' instead of 'friends'. That should do it.