7. Search


#1

var friends = {
bill: {
firstName: "Bill",
lastName: "One",
number:"(705) 928-8893",
address: ['1131 adirondack dr']
},
steve: {
firstName: "Steve",
lastName: "One",
number:"(705) 928-8893",
address: ['1131 adurondaock dr']
},
mark: {
firstName: "Mark",
lastName: "One",
number:"(705) 928-8893",
address: ['1131 adirondakcn dr']
}
}
var list = function (friends) {
for (var bill in friends) {
console.log(bill);
}

};

var search = function (name) {
for (var find in friends) {
if(friends[find].firstName === name) {
console.log(friends[find]);
}
else {
return 'not found';
}
}
};
list(friends);
search("Steve");

Cant find info for steve. not sure what to do


#2

This is my code:

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

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

};
search("Steve");

I think if you replace "find" with "key," that could make a difference. Also, you never returned friends[key]; in your if statement.