[Contact List 7/8] Please Help me to figure out why my code doesn't work. Thanks so much


#1


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


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


var friends = {};
friends.bill = 
{
    firstName: 'Bill',
    lastName: 'fox',
    number: '0912345678',
    address: ['One Microsoft Way','Redmond','WA','98052']
};
friends.steve = 
{
    firstName: 'Steve',
    lastName: 'johnson',
    number: '0425368157',
    address: ['One Microsoft Way','Wohaa','CK','11110']
};

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

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


#2

this line:

if(friends[key].firstName === true)

why do you compare the first name in the objects with true? I don't understand, your search function has a parameter (name) which holds the name when you search for the function, so you should use name to compare with the firstNames in the objects


#3

We want the expression to evaluate to true, not be 'true'. For that, give a name.

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

#4

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