7. Search For A Friend


#1



Hey all, I'm stuck here: https://www.codecademy.com/courses/javascript-beginner-en-3bmfN/0/7?curriculum_id=506324b3a7dffd00020bf661#. I have no idea what I'm doing wrong.


When I run it, it logs this "["One Apple Way","Redmond","WA","98052"]". Any help is appreciated, thanks!


var friends = new Object ();
    
    friends.bill = new Object ();
        friends.bill.firstName = "Bill";
        friends.bill.lastName = "Gates";
        friends.bill.number = "(333) 333-3333";
        friends.bill.address = ["One Microsoft Way", "Redmond", "WA", "98052"];
    friends.steve = new Object ();
        friends.steve.firstName = "Steve";
        friends.steve.lastName = "Jobs";
        friends.steve.number = "(999) 999-9999";
        friends.steve.address = ["One Apple Way", "Redmond", "WA", "98052"];
        
var list = function (friends) {
    for (var listing in friends) {
        console.log(listing);
    }
}

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


#2

Hi first your function search should have as argument name instaed of friends then this line

if(friends[searching].firstName === "Steve")

in this case the search function will only search for "Steve" so instead of "Steve" you should put the argument of the function search.


#3

This post was flagged by the community and is temporarily hidden.


#4

Try this one

var friends = {
bill: {
firstName: "Bill",
lastName: "Gates",
number: "2734",
address: ["New York"]
},

steve: {
    firstName: "Steve",
    lastName: "Great",
    number:"2734",
    address:["Los Angeles"]
    }


};

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

 var search = function(name){
    for(var searching in friends){
    if(friends[searching].firstName === name)
    {

console.log(friends[searching]);
return friends[searching];
}

       }

    };