7.Search for a friend ( Why did it log 3 times )?


#1

Why did this function log to the console 3 times repeating instead on one?

The entire function:

var friends = new Object();

friends.bill = new Object() ;
friends.bill.firstName = "Bill";
friends.bill.lastName = "Jones";
friends.bill.number = "707-555-1234";
friends.bill.address = ['Sixty Nine Street','Blow Job Town','CA','80932'];
friends.steve = new Object() ;
friends.steve.firstName = "Steve";
friends.steve.lastName = "Skuba";
friends.steve.number = "707-555-4321";
friends.steve.address = ['117 Master Cheif Lane','Nippleville','WA','39811'];

var list = function (friends) {
for(var list in friends ) {

    console.log(list) ;
}

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

The Console Screen

{ firstName: 'Bill',
lastName: 'Jones',
number: '707-555-1234',
address: [ 'Sixty Nine Street', 'Blow Job Town', 'CA', '80932' ] }
{ firstName: 'Bill',
lastName: 'Jones',
number: '707-555-1234',
address: [ 'Sixty Nine Street', 'Blow Job Town', 'CA', '80932' ] }
{ firstName: 'Bill',
lastName: 'Jones',
number: '707-555-1234',
address: [ 'Sixty Nine Street', 'Blow Job Town', 'CA', '80932' ] }
{ firstName: 'Bill',
lastName: 'Jones',
number: '707-555-1234',
address: [ 'Sixty Nine Street', 'Blow Job Town', 'CA', '80932' ] }
{"firstName":"Bill","lastName":"Jones","number":"707-555-1234","address":["Sixty Nine Street","Blow Job Town","CA","80932"]}


#3

I am no expert but I believe that in your if statement you have the wrong input so instead of saying if this matches with the name of the function we are running you are saying if "steve" || "bill" so it is putting that information multiple times. Try changing that (see my suggestion below) and see if it works.

    if(friends[x].firstName === name) {
       console.log(friends[x]);
        return friends[x];

}
else {
console.log("I don't know that person");
}
}
};

search ("bill");
search ("steve");