7. Search for a friend


#1

I have no idea how to do this and I have no idea what I did wrong.
Any help? :cry:
NEVERMIND!
I realized it was the spaces after the strings.

var friends = {

bill:{
firstName: "Bill ",
lastName:"Gates ",
number: "(267) 555-5555",
address:["689 Snyder st. Orange County, PA 19111"]
},
steve:{
firstName: "Steve ",
lastName:"Jobs ",
number: "(267) 556-5555",
address:["688 Snyder st. Orange County, PA 19111"]
},
matt:{
firstName: "Matt ",
lastName:"Marshall ",
number: "267 557-5555",
address:["687 Snyder st. Orange County, PA 19111"]
}
};
var list = function(friends) {
for (var firstName in friends){
console.log(firstName);
}
};
var search = function(name) {
for(var key in friends) {
if(friends[key].firstName === name) {
console.log(friends[key]);
return friends[key];
}
}

};
search("Steve");


#2

try changing key to friends


#3

I've came to this problem too. what's wrong indeed?


#4

He had a space between Steve and double quotation marks( firstName: "Steve ")
search("Steve") didn't have the space.
"Steve " != "Steve" so the function couldn't find the name.


#5

I added spaces after the strings in firstName.
But when I called the function "Steve" I did not include the space so Steve's contact info was never returned.