Ops, try again. It looks like your search function doesn't return contact information for Bill


#1

var friends = {
james: {
firstName: "James",
lastName: "Elias",
number: "555-555-5555",
address: ['One Microsoft Way','Redmond','WA','98052']
},
james2: {
firstName: "James2",
lastName: "Nguyen",
number: "555-555-5555",
address: ['One Microsoft Way','Redmond','WA','98052']
},
bill: {
firstName: "bill",
lastName: "thai",
number: "555-555-5555",
address: ['One Microsoft Way','Redmond','WA','98052']
},
steve: {
firstName: "Steve",
lastName: "Nuggent",
number: "555-555-5555",
address: ['One Microsoft Way','Redmond','WA','98052']
}
};

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].firstName);
return friends[key];
}
}
};

search("bill");

It works but doesnt let me pass. I tried console.log(friends[key]); as well and it says the same thing but also prints the the info multiple times thats why i put the firstName there


#2

Here:

You should just be printing out friends[key] only. Also, since bill is the first name, which you did rather manually/handcoded, you should search for ("firstName")


#3

I tried printing only friends[key] and it still doesnt work, it just makes it print the info multiple times. What do u mean search for ("firstName")? Lke when i call the function?


#4

bill
Steve
Steve
{"firstName":"bill","lastName":"thai","number":"555-555-5555","address":["One Microsoft Way","Redmond","WA","98052"]}

this is the output the way i do it.


#6

Ok so all i did was go to the object and Capitalize the firstName key from "bill" to "Bill" and it worked....im confused as to why that made it work but yea...wtf lol


#7

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.