7.Search for friend


#1

Dear friends,

Please help me to resolve my code
var friends = {};
friends.bill = {
firstName: "Duglas",
lastName: "Costa",
number: "(095) 212-32576",
address: ['st. Shevchenko','Riasne','UA','360/20']
}
friends.steve = {
firstName: "Andriy",
lastName: "Shevchenko",
number: "(093) 973-2148",
address: ['Shevchenka','Riasne','UA','45/40']
}
var list = function() {
for ( i in friends) {
console.log(i);
}
//list();
}
var search = function(name) {
for (var key in friends.steve) {
if (friends[key].firstName === name) {
console.log (friends[key]);
return friends [key];
}
}
//search();
};

The problem is "Did you create the function called search?"
But I have the answer


#2

the aim is to search through your friends list not just steve's


#3


#4

I have tried to do it twice but nothing special happen maybe do you something else on your thought


#5

are the credentials for steve what was originally given in module?


#6

Here is my solution (I used the other method to create the objects):

var friends = new Object();

friends.bill = new Object();
friends.steve = new Object();

friends.bill.firstName = "Bill";
friends.bill.lastName = "Gates";
friends.bill.number = "(620) 640-0001";
friends.bill.address = ["st city st"];

friends.steve.firstName = "Steve";
friends.steve.lastName = "Jobs";
friends.steve.number = "(620) 640-0002";
friends.steve.address = ["st city st"];

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

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


#7

Hello Spkoehn,

Could you please explain your method,
Please provide a few comments from your side,

I have to admit how good your code is


#8

Again your code is not wrong.The reaon you are no passing is because the credentials(details) for the steve and bill property(object) are not what was originally given in the course. That is what the tester expects


#9

Ok, thank you for your little help in my case,
have a wonderful day ahead


#10

Copy Pasting your solution prints out in console 3 times the profile of steve lets say, so is not quite the right solution. Thx anway