Says i didn't create a function called search


#1


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


SEARCH FOR A FRIEND
It always shows me this message when I click on Save and Submit: "Oops, try again. Did you create a function called search?"


var friends = {};
friends.bill = 
{
    firstName: "Bill",
    lastName: "Nye the Science Guy",
    number: "420",
    address: ["sciencekidslane", "nerdsville"]
};
friends.steve = 
{
    firstName: "Steve",
    lastName: "from Minecraft",
    number: "666",
    address: ["blockroad", 555, "legoworld"]
};
friends.bob = 
{
    firstName: "Bob",
    lastName: "the Builder",
    number: "69",
    address: [232, false, 7438]
};

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

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


#2

The problem is here, change object to friends.


#3

Hello,

I am having the same error, please help me out, even though I am calling the object friends. My code is as follows:

var bill = new Object();
var steve = new Object();
var friends = {
bill : {
firstName : "Bill",
lastName : "Stevens",
number : "(245) 236-2387",
address : ['One Microsoft Way','Redmond','WA','98052']
},
steve : {
firstName : "Steve",
lastName : "Williams",
number : "(556) 837-9089",
address : ['4/21 A','Sahid Nagar','CA','700031']
}
};
var list = function(friendNames){
for (var i in friends){
console.log(i);
}
}
var search = function(name){
for (var j in friends){
if (name === friends[j].firstName){
console.log(friends.number[j]);
return friends[j];
}
}
};

Regards,
Madhumita


#4

Your problem is here you should check the firstName first and then name,

So like,

if (friends[j].firstName === name)

And lastly,

You need to just print the same thing as your return so just,

 console.log(friends[j])

#5

Hi bandit,

I have made the changes as per your suggestion. Still it is asking me, if I have created a function called search. I don't know where I am going wrong now.


#6

Let me see your updated code


#7

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