7.Search for a friend


#1

var friends = {
bill: {
firstName: "Bill",
lastName: "Gates",
number: "(206) 555-5555",
address: ["Microsoft", "Wa"]
},
steve: {
firstName: "Steve",
lastName: "Jobs",
number: "(207) 555-5555",
address: ["Gigi Becali Street", "Chuck Norris's Universe"]
}
};
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 === name) {
console.log(friends[key]);
return friends[key];
}
else {
list(friends);
search("Steve");
}
}
};

Can somebody please tell me what I got wrong?


#2

var friends = {
bill: {
firstName: "Bill",
lastName: "Steve",
number: "(123) 456-7890",
address: ['One Microsoft Way', 'Redmond', 'WA', '98052']
},
steve: {
firstName: "Steve",
lastName: "Bill",
number: "(0987) 654-321",
address: ['Apple Avenue', 'Apple', 'AP', '49913']
}
};
var list = function(friends) {
for(var key in friends) {
console.log(key);
}
}
var search = function(name) {
for(var key in friends) {
if(friends[key].firstName === name) {
console.log(friends[key]);
return friends[key];
}
}
};

I believe your issue is because your else in your if/else statement