7. search for a friend, need help!


#1

var friends = {
bill: {
firstName: "Bill",
lastName: "Moody",
number: "055 555 555",
address: ["ergens in de wereld", "in azie"]
},

steve:{
firstName: "Steve",
lastName: "Jobs",
number: "0594 644 58",
address: ["ook ergens in de wereld", "sadkfj"]
}

};

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

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

    }
}

};
list(friends);
search(bill);


what am i doing wrong?
thanks in advance


#2

@mausje,

-1

Change your search function into

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

-2

In the call of your search-function
you will have to use an argument which has a string Value
like

search("Bill");

====================================

You will be confronted with multiple output....
Please read
= http://discuss.codecademy.com/t/6-8-a-question-of-why-i-get-the-result-i-get/10666/10?u=leonhard_wettengmx_n