JavaScript Problem in the search function!


#1

"I have a problem in the search function, exercise says that my function does not return the information from steve, what do I do to fix it? Help me please!"
var friends = {
steve : {firstName: "Steve Paul", lastName: "Jobs", number:"(250)92333-345", address: ["Palo Alto", "56930"]},
bill : {firstname:"Bill Henry", lastname: "Gates 3", number:"(250) 93434-353", address: ["Oakland", "4647"]}
};
var list = function(friends) {
for (var bill in friends) {
console.log(bill);
} };
var search = function(name) {
for(var steve in friends) {
if (friends[steve].firstName === name) {
console.log(steve);
return friends[steve];
}
}
};
search("Steve Paul");


#2

Is this a lesson in the Portuguese track? Looks like the English track. Please advise so we can move it to the correct category.

One bit of advice I would offer is to use generic terms for local variables, not the keys of your objects. bill and steve are keys, and make for confusing variable names in a function.

for (var key in friends)

I'm not sure if the instructions expect us to write,

var list = function (friends) {

};

Can we get away with using a generic as the parameter?

var list = function (object) {
    for (var key in object) {

    }
};

That way we can use the function to list the keys of any object, not just friends.

Apply the generic key to your search function and see if it makes a little more sense to you...