Search for a friend*****


The course passes me to the next step as if this code is correct but the editor outputs my code, not name.
I have read others’ posts and written this search function while not really understanding if it would work using X,Y and Z instead of firstName, name etc. Can someone review this for me? Thanks. I have read all the long post responses. They are informative but I’m just not getting it.

var friends = {
    bill: {
        firstName: "Bill",
        lastName: "Gates",
        number: "(206) 555-5555",
        address: ['One Microsoft Way', 'Redmond', 'WA','98052']
    steve: { 
        firstName: "Steve",
        lastName: "Jobs",
        number: "(206) 555-3333",
        address: ['34 Bay Drive', 'Seattle', 'WA','98052']
    joanie: {
        firstName: "Joanie",
        lastName: "Cat",
        number: "(555) 555-1212",
        address: ['12 MainCat Ave','Las Vegas','NV','89222']
var list = function(friends){
    for (var firstName in friends)
    { console.log(firstName);}
var search = function(name){
    for (var firstName in friends ){
        if(friends[firstName].firstName === name){
        return friends


This can be confusing since it looks identical to a property name. Better to use a generic variable name, such as, key which describes its programmatic role, to hold a key name.

On the whole, though, your code runs and passes because it is syntactically and logically correct.


Thanks. Yes, I see how using a more generic variable is useful. I was getting them confused.