My code is not working for some reason. need help!


#1

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

Why is this not working? I'm frustrated.

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


var friends = new Object();

friends.bill = {
    firstName: "bill",
    lastName: "anderson",
    number: "0732456765",
    address: ['hasslerorsvagen', 14, 54272, 'Mariestad', 'Sverige']
};
friends.steve = {
    firstName: "steve",
    lastName: "peterson",
    number: '0732873942',
    address: ['tomtevagen', 54, 34653, 'Flakmopedstaden', 'Finland']
};

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

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

search("steve");


#2

Please don't be frustrated. You should be doing:

console.log(friends[key]);

And not:

Then, you should do:

search("firstName");

And not:


#3

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