7. search for a friend


#1

Hi,
can somebody help me? Thanks

<var friends = new Object();
friends.bill = {};
friends.steve = {};

var friends = {
bill:{
firstName: "Bill",
lastName: "Engler",
number: "0049 111 00 00 00",
address: ['Martinstrasse','112','12345','Berlin']
}
};
var friends = {
steve:{
firstName: "Steve",
lastName: "Schneider",
number: "0049 000 00 11 11",
address: ['Georgesstrasse', '334', '67890', 'Frankfurt']
}
};

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];
}
}
};

list();
search("Bill");>


Oops, try again. It looks like your search function doesn't return contact information for Bill.

Output:
{ firstName: 'Steve',
lastName: 'Schneider',
number: '0049 000 00 11 11',
address: [ 'Georgesstrasse', '334', '67890', 'Frankfurt' ] }
{ firstName: 'Steve',
lastName: 'Schneider',
number: '0049 000 00 11 11',
address: [ 'Georgesstrasse', '334', '67890', 'Frankfurt' ] }


#2

The second object is overwriting the first. Write both objects inside the friends object. Remember to separate them with a comma.


#3

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