7/8, someone please help me what's wrong with this code?


#1

Been stuck for a while on this now :confused:

var friends = {
bill: {
firstName: "Bill",
lastName: "Gates",
number: "(206) 555-5555",
address: ['One Microsoft way','Redmond','WA','98052']
},
steve: {
firstName: "Steve",
lastName: "Jobs",
number: "(206) 666-6666",
address: ['One Apple way','Redmond','WA','96042']
}
};

var list = function (friends) {
    for (var yo in friends) {
        console.log(yo);
    }
};

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

list (friends);
search("steve");


#2

are creating or learning it?


#3

I'm currently learning it


#4

It doesn't work for me either, I wrote it in a similar way.


#5

I can't get mine to work either, so this might not be everything, but i think you need to change the parameter of your search function from friends to 'name'. Think about when you actually do the search, you will give it a name, which is then compared to the array friends.


#6

Can't get mine to work either. Still trying to figure out this whole for/in loop malarkey. However in your code @weemaniac
var search = function (friends) {
for(var key in friends) {
if(friends[key].firstName === name) {
console.log(friends[key]);
return friends[key];
}
}
};

you haven't defined name. It should probably be the parameter of the function ie var search = function (name)