7. Search for a friend :P


var friends = {};

friends.bill = {
firstName: "Bill",
lastName: "Showers",
number: "303-678-9221",
address: ["Castle Rock", "CO"]

friends["steve"] = {};

friends.steve["firstName"] = "Steve";

friends.steve["lastName"] = "Garrets";

friends.steve["number"] = "3038907814";

friends.steve["address"] = ["Tiger", "Army"];

var list = function(x){
for (var key in x)

//Catonyourhead here! here's what i'm stuck on... I thought I understood... guess not!
//I would love to hear your reasoning as to why this code prints undefined, rather than the information at the coordinates I thought I had provided. Can't you use the passed in variable as a coordinate(key)? or did I do something wrong? Also, if you think I'm unclear on anything else, I'm very willing to learn!

var search = function(name){
for (var x in friends){
if (x === name.toLowerCase()){


You're accessing the attribute x of friends.. and it has no such attribute, it's undefined

You do have a variable called x in that scope though, perhaps use that instead.


isn't x my local variable for substitution of each item in my list? and if so, wouldn't using friends.x turn into friends.(whichever name is being used) ? Please help. I guess I am unclear.


Whenever you put a dot . after something, you're accessing something in that scope, in this case the scope of friends. And in that scope, there is no x.

Use friends[x] instead, which is lookup by value.