My search function doesn't return contact info for Steve, and I don't know why


#1



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


My code matches the "Stuck? Get a hint" box, but it doesn't return contact info for Steve. Can anybody help me out?

var friends = {
    bill: {
        firstName: 'Bill',
        lastName: 'Gates',
        number: '(800) 825-1000',
        address: ['One Microsoft Way', 'Redmond', 'WA', '98052']
    },
    steve: {
        firsName: 'Steve',
        lastName: 'Jobs',
        number: '(555) 555-5555',
        address: ['1600 Pennsylvania Avenue NW', 'Washington', 'DC','20500']
    }
};
var list = function(contacts){
    for (var firstName in contacts){
        console.log(firstName);
    }
}

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


#2

What information should your function print and return?
And which information do you print/return?


#3

It should display both properties of friends (bill and steve) with the list function, and display the properties of the object of the searched object (the properties of bill or steve). Right now, it displays both bill and steve, but only shows the properties of bill, no matter what.


#4

Codecademy has a bad tendency to print out the last value used.

You could add this at the bottom of your code:

console.log("============================");

And then you'll know that anything below that is not from your own code.
I imagine that you're no longer printing properties for anyone, you're printing something else.


#5

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