7. Search for a friend


#1

Why my code input me all information about all contact?
Code:

var friends = {
bill: {
firstName:"Bill",
lastName: "Gates",
number: "(206) 555-5555",
address: ['One Microsoft Way', 'Redmond','WA','98052']
},
steve:{
firstName:"Steve",
lastName: "Kormack",
number: "(321) 543-3465",
address: ['1st infinity loop', 'Cupertino','CA','45327']
},
geka:{
firstName:"Geka",
lastName: "Yoo",
number: "(925) 555-5555",
address: ['Ул.Станиславского', 'Батайск','РО','151213']
}
};

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

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

list(friends);
search("Geka");

Input

bill
steve
geka
{ firstName: 'Geka',
lastName: 'Yoo',
number: '(925) 555-5555',
address: [ 'Ул.Станиславского', 'Батайск', 'РО', '151213' ] }
{ firstName: 'Steve',
lastName: 'Kormack',
number: '(321) 543-3465',
address: [ '1st infinity loop', 'Cupertino', 'CA', '45327' ] }
{ firstName: 'Steve',
lastName: 'Kormack',
number: '(321) 543-3465',
address: [ '1st infinity loop', 'Cupertino', 'CA', '45327' ] }
{ firstName: 'Bill',
lastName: 'Gates',
number: '(206) 555-5555',
address: [ 'One Microsoft Way', 'Redmond', 'WA', '98052' ] }
{"firstName":"Geka","lastName":"Yoo","number":"(925) 555-5555","address":["Ул.Станиславского","Батайск","РО","151213"]}


#2

@alias08,
In some sections of this course, the course-checker Display's data
this you could then identify by placing two EXTRA code-line's:
console.log( "== My End ==" );
console.log( "== All that is displayed now, is the course-checker ==" );

Try it by extending your code
like

list(friends);
search("Geka");
console.log( "== My End ==" );
console.log( "== All that is displayed now, is the course-checker ==" );

#3

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