7.search for a friend ..Oops, try again. It looks like your search function doesn't return contact information for Steve


#1

<

friends.steve.firstName="steve";
friends.steve.lastName="williams";
friends.steve.number="(085) 200999 land";
friends.steve.address=['mg road','blr','582034']
var list=function(obj)
{
    for(var com in obj)
    {
        console.log(com);
    }
};
var search=function(name){
    for(var com in friends)
    {
        if(friends[com].firstName===name){
            console.log(friends[com]);
            return friends[com];
        }
        
    }
};
list(friends);
search("steve");

please help me i don't know what's wrong with you my code.Thank You!


#2

Is this the whole program? If so, friends is undefined, steve is undefined...

If not please share the full code as well as all error messages (if the console gives a separate error message) and what the output is. In the future a link to the lesson would also be helpful. :slight_smile:


#3

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

please check it out


#4

@arathi, thank you for the link to the lesson. It is helpful as a reference for the lesson objective.

Unfortunately, the way the site is set up, I can only see only my program in there, not yours. :disappointed: If this is not your full program I recommend you edit your post to show all the code and your error message. :slight_smile:


#5

var friends = new Object();
friends.bill=new Object();
friends.bill.firstName="bill";
friends.bill.lastName="jacob";
friends.bill.number="(085)202999 land";
friends.bill.address=['richmond road','bngr','560034']
friends.steve=new Object();
friends.steve.firstName="steve";
friends.steve.lastName="williams";
friends.steve.number="(085) 200999 land";
friends.steve.address=['mg road','blr','582034']
var list=function(obj)
{
for(var com in obj)
{
console.log(com);
}
};
var search=function(name){
for(var com in friends)
{
if(friends[com].firstName===name){
console.log(friends[com]);
return friends[com];
}

}

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

complete code.


#6

Do you have an error message?


#7

yeahh..

Oops, try again. It looks like your search function doesn't return contact information for Steve.


#8

Hi,

Tricky problem.

In an earlier lesson, instructions say:

Give each of your friends a firstName, lastName, and number. The value for each of these should be a string (check the Hint if you need help). Make sure bill's first name is "Bill" and steve's first name is "Steve" (again, note the capitalization).

I didn't see any errors in your program when I looked over it, but I think the lesson wants Steve and Bill, not steve and bill.

Try replacing "steve" with "Steve" in your properties and maybe your error message will change to "bill". Then try capitalising "bill" and see if it works. It worked over here so possiby that's the issue...


#9

that's the problem.Thanku so much!!


#10

Great! No problem :slight_smile: Good luck with the rest of the track :nerd: