7. Search for a friend failed return results


#1

Hello Everyone,
This seems to be a common issue a lot of people are having. But when I run my code, I receive 'Oops Try Again! Function doesn't return contact info for ...'


var friends = {
bill: {
firstName: 'Bill',
lastName: 'Gates',
number: '(555) 555-5555',
address: ['8571 Haxton Cir.']
},
steve: {
firstName: 'Steve',
lastName: 'Jobs',
number: '(555) 555-5555',
address: ['8571 Haxton Cir.']
}
};
var list = function(friends) {
for (var firstName in friends) {
console.log(firstName);
}
};
var search = function(friends) {
for (var firstName in friends) {
if(friends[firstName].firstName === name) {
console.log(friends[firstName]);
return friends[firstName];
}
}
};
list(friends);
search('Steve')



#2

SOLVED! I re-read the hints provided in the lesson and played around with some of the key identifiers.

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