7 Search for a friend


#1

I am receiving a reference error firstName is not defined in this code. What am I doing wrong?var friends = new Object();
friends.bill ={
firstName:"Bill",
lastName: "Gates",
number: "23",
address: ['One Microsoft', 'Silicone', 'CA', '123456']
}
friends.steve ={
firstName:"Steve",
lastName: "Jobs",
number: "24",
address: ['123 hooter', 'booker', 'OK', '233432']
}
friends.Josh ={
firstName:"Josh",
lastName: "Leck",
number: "34",
address: ['123 claire', 'dancy', 'KS', '233411']
};
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[firstName]);
return friends[key];
}
}
};
list(friends);
search("Steve");


#2

This line is the problem console.log(friends[firstName]);.
It should be console.log(friends[key]); because your keys are bill, steve and ˛Josh. You want to use console.log() on object with given key, not on friends[firstName].