Search Steve :( help me please!


#1


this is an error that i got
. "It looks like your search function doesn't return contact information for Steve"


var friends = {
    bill: {
        firstName : "Bill",
        lastName : "Gates",
        number : 12345678,
        address :['BCN street','american',24],
        },
    steve :{
        firstName : "Steve",
        lastName : "Jobs",
        number : 12345679,
        address :['montblanc street','american',24],
        },
    tom : {
        firstName : "Tom",
        lastName : "Hank",
        number : 12345698,
        address :['hollywood','american',24],
        },
};
var list = function (friends) {
  for (var key in friends ){
  console.log (key);
  }
};
var search = function (friends){
    for (var key in friends) {
        if (name === friends[key].firstName) {
            console.log(friends[key]);
            return friends[key];
        }
    }
};
search("Steve");


#2

the problem is in your function parameter:

var search = function (friends)

the parameter is what you are comparing with:

if (name

so in your case the function parameter should be friend, since friend is a placeholder variable which will hold a value the moment you call a function (the argument you pass into the function when calling)


#3

thank you so much :smiley: it worked


#4

do you also understand why it works?


#5

at first i was thinking since i made the function (friends) and all names are inside that function so when i want to call the name i just put name in this if (name === friends[key].firstName) { to call it out. but i have to call the holder of those variables .


#6

no, you just have access to the object anyway, the parameter is the name you want to search for. You seem to understand now


#7

thanks to you :smile: