Identify the problem


#1

Can you tell me what's wrong here?


The error message:

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



My code:

var friends = {};
friends.tovy = {
    firstName: 'Ron',
    lastName: 'Tovy',
    number: '(999) 345-6789',
    address: ['My best friend', 'Another thing that tells pesonal informasion about him', 'MuHaHaHa']
};
friends.bill = {
    firstName: 'Bill',
    lastName: 'Gates',
    number: '(206) 555-5555',
    address: ['One Microsoft Way','Redmond','WA','98052']
};
friends.steve = {
    firstName: 'Steve',
    lastName: 'Shir',
    number: '(111) 123-2123',
    address: ["Do you like my new shoes?", "Honey, you are a chair.", "I can dream, Merold!"]
};
var list = function(obj) {
    for (var key in obj) {
        console.log(key);
    }
};
list(friends);
var search = function(name) {
    for(var key in friends) {
        if (name === key.firstName) {
            console.log(key);
            return key;
        }
    }
};
search('Steve');


Thanks, Ron Dankner


#2

You have wrong syntax. To get access to nested object property you need to use:

friends[key].firstName;

Function returns contact information, so it's should be an object: friends[key].

In your case key are names of nested objects: tovy, bill, steve. But it are not objects.


#3

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