Contact List - Search for a friend


#1


Oops, try again. Did you create a function called search?
I know that I created a function called search so what is wrong?


var friends = {
    bill: {
        firstName:"Bill",
        lastName:"smith",
        number: 813-224-3844,
        address: ["343 Hoken Street","Miami","FL"]
        },
    steve: {
        firstName: "Steve",
        lastName: "Jefferson",
        number: 2,
        address: ["123 Main boulevard","Tampa","FL"]
        }
    
    }; 
var list = function(thing){
    for(var thing in friends){
        console.log(thing);
    }
}
var search = function(name) {
    for(var name in friends) {
        if(name === freinds[name].firstName){
            console.log(friend[name]);
            return friend[name];
            }
        }
}


#2

Hey there,

Try calling search() function in the end and passing either "Bill" or "Steve".

But before you do that, fix typos! :smiley:

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


#3

Hey I fixed the typos and wrote search("steve"); at the bottom and click submit
and it said "Oops, try again. Did you create a function called search?" once again


#4

Is for(var name in friends) right? I am very confused how those for loops work


#5

Yeah I feel you, been there. No worries, you will grasp it eventually! All in good time - let some time pass and brush it up :wink:

Actually you should consider changing var to something different than "name" in your for loop. You are already passing it as an argument to the search function. Try replacing it with smth different, property for example.

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

#6

Hi simon,

At a glance, your code looks fine, so I assume it's the checking on codecademy.com side.

I assume what you posted is your whole code.
You created the function, when will you call it? (I suppose this is what codecademy looking for)

add in the bottom:
search("Bill");


#7

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