Contact list input method - search friend name


#1

Hi,

I used the other method taught in a previous section to enter contact info for this exercise. It appeared to work ok up until part 7 where I am required to create a search function. Then I get an error message stating "Oops, try again.
It looks like your search function doesn't return contact information for Steve."

It seems the problem is with how I have entered the objects since when I use the object code given in the "what you will be building" section, my search function seems to work ok. Can anyone see where I am going wrong? I am struggling and feeling a deep sadness.

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


//the problem code

var friends = {};
    friends.bill = {}
        friends.bill.firstName = "Bill"
        friends.bill.lastName = "Gates"
        friends.bill.number = "0121 do one"
        friends.bill.address = ["One Yewcant Av.", "My Address", "America Maybe"]

    friends.steve = {}
        friends.steve.firstName = "Steve"
        friends.steve.firstName = "Jobs"
        friends.steve.number = "0870 you cant have my number bro"
        friends.steve.address = ["The Mansion", "Canta Fjoord", "Denmark"]

/* from here below appears ok when I replace the above with the following:

var friends = {};
friends.bill = {
  firstName: "Bill",
  lastName: "Gates",
  number: "(206) 555-5555",
  address: ['One Microsoft Way','Redmond','WA','98052']
};
friends.steve = {
  firstName: "Steve",
  lastName: "Jobs",
  number: "(408) 555-5555",
  address: ['1 Infinite Loop','Cupertino','CA','95014']
}; */

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

search("steve");


#2

Search looks for a name in friends objects, not a key in friends.

search("Steve");

#3

Hi, thanks for the reply. I changed that around and it still gives the same error.


#4

print out the friends and see for yourself if there's anyone with first name Steve


#5

Hahaaaa! I got it.

So stupid too. Two entries for firstName - so Steve's first name was replaced as Jobs. Thus no Steve.

Thanks for the help.