Oops, try again. Did you create a function called search?


#1


https://www.codecademy.com/courses/javascript-beginner-en-3bmfN/0/7?curriculum_id=506324b3a7dffd00020bf661#

I keep getting this error:

Oops, try again. Did you create a function called search?

I've looked at this and checked the forums for an answer and I can't work it out. Please help, what is wrong with my code in regards to the search function?!


var friends = {
    
    bill: {},
    steve: {},
    george: {},
    
};


friends.bill = {
    
    firstName: "Bill",
    lastName: "Cosby",
    number: "9731",
    address: ["14 Crowmwell", "South Kensington", "London", "GF56 TY1"],
};

friends.steve = {
    
    firstName: "Steve",
    lastName: "Johnson",
    number: "6734",
    address: ["17 Old Street", "East", "London", "EC1M 7TR"]
};

friends.george = {
    
    firstName: "George",
    lastName: "Baker",
    number: "11135",
    address: ["140 Abbotts Drive", "Stanford le Hope", "Essex", "SS17 7BT"]
};

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

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


#2

You forgot about name argument in your search() function.

var search = function(name) {
// ...
}

Also, you should change variable name in for loop from steve to key to get this working.


#3

Thank you it works now!