7. Search for a friend


#1

Not sure what I'm doing wrong. This is my code:

var friends = {

bill: {
firstName: "bill",
lastName: "gates",
number: "206-555-1234",
address: ['One Microsoft Way', 'Redmond', 'WA', '98052']
},

steve: {
firstName: "steve",
lastName: "jobs",
number: "415-555-1234",
address: ['1 Infinite Loop', 'Cupertino', 'CA', '95014']
}
};

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

search('steve');

Error message:
Oops, try again. It looks like your search function doesn't return contact information for Steve.

Output:
{ firstName: 'steve',
lastName: 'jobs',
number: '415-555-1234',
address: [ '1 Infinite Loop', 'Cupertino', 'CA', '95014' ] }
{"firstName":"steve","lastName":"jobs","number":"415-555-1234","address":["1 Infinite Loop","Cupertino","CA","95014"]}

Thinking it has something to do with my function, but I'm not sure at this point. It might be me looking at this for WAY too long, or something else entirely. Thanks y'all.


#2

@teraninja09473,

1

The course expects
the firstName-Value to start with a capitalized character like "Steve" and "Bill"

So change those Value's and then use

 search(''Steve");

2

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


#3

Yeah, I just capitalized the names within the objects and the name in the search function. Thank you!