Help - Search for a friend


#1


https://www.codecademy.com/en/courses/javascript-beginner-en-3bmfN/0/7?curriculum_id=506324b3a7dffd00020bf661

This is my code and my output. Any help is appreciated. Thank you.

var friends = { };

friends.bill = {
firstName: 'Bill',
lastName: 'Johnson',
number: '(312) 555-5555',
address: ['500 Independence Street','Yakima','WA','95823']
};
friends.steve = {
firstName: 'Steve',
lastName: 'Markowitz',
number: '(773) 506-8932',
address: ['2520 Yancey Boulevard','Beetlesboro','GA','36051']
};

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

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

This is my output:

{ firstName: 'Steve',
lastName: 'Markowitz',
number: '(773) 506-8932',
address: [ '2520 Yancey Boulevard', 'Beetlesboro', 'GA', '36051' ] }
{ firstName: 'Steve',
lastName: 'Markowitz',
number: '(773) 506-8932',
address: [ '2520 Yancey Boulevard', 'Beetlesboro', 'GA', '36051' ] }
{ firstName: 'Bill',
lastName: 'Johnson',
number: '(312) 555-5555',
address: [ '500 Independence Street', 'Yakima', 'WA', '95823' ] }
{"firstName":"Steve","lastName":"Markowitz","number":"(773) 506-8932","address":["2520 Yancey Boulevard","Beetlesboro","GA","36051"]}



#2

Hello @andyville130,

What error message is it showing you? Thanks!


#3

Hi.
It's not showing an error message. But the output is showing my version of "Steve" three times and my version of "Bill" one time. It just doesn't look right to me.


#4

Hey @andyville130,

But is the exercise letting you pass... If so, then the console is printing out Codecademy's additional checks that check if your exercise is valid...


#5

{ firstName: 'Steve',
lastName: 'eve',
number: '(555) 555-5555',
address: [ '555 five road', 'las vegas', 'NV' ] }
{ firstName: 'Steve',
lastName: 'eve',
number: '(555) 555-5555',
address: [ '555 five road', 'las vegas', 'NV' ] }
{ firstName: 'Bill',
lastName: 'lib',
number: '(123) 456-7890',
address: [ '123 four street', 'las vegas', 'NV' ] }
{"firstName":"Steve","lastName":"eve","number":"(555) 555-5555","address":["555 five road","las vegas","NV"]}

This is the output I get for the coding,
var list = function (friends) {
for(var key in friends) {
console.log(key);
}
};

var search = function (name) {
for(var key in friends) {
if(friends[key].firstName === name) {
console.log(friends[key]);
return friends[key];
}
}
};
Can someone explain me the output?


#6

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