Getting some odd results


#1


var friends = new Object();

var friends = {
    bill: {
        firstName: "Bill",
        lastName: "Gates",
        number: "(395) 443-4543",
        address: ['One Microsoft Way','Redmond','WA','98052'],
    },
    steve: {
        firstName: "Steve",
        lastName: "Jones",
        number: "774-857-9964",
        address: ['78495 Strattleburg Crt','Wilbur','AK','12548']
    },
    carl: {
        firstName: "Carl",
        lastName: "Johnson",
        number: "552-145-6375",
        address: ['6969 BS Pkwy', 'OhYeah', 'NJ', '55489']
    }
};

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

var search = function(friends) {
    for (var h in friends) {
        if ( friends[h].firstName === "Bill" || "Steve" || "Carl" ) {
            console.log(friends[h]);
            return friends[h];
        } 
        else {
            console.log("Sorry bro I don't have that name listed");
        }
    }
};


This is resulting in the following log to console:


S
S
B

  1. Contact List ( https://www.codecademy.com/courses/javascript-beginner-en-3bmfN/0/7?curriculum_id=506324b3a7dffd00020bf661# )

Also tried it with

if ( friends[h].firstName === name )

with resulting log to console:

Sorry bro I don't have that name listed
12x, or the number of keys in object?

Furthermore, both resulted in the following error message:

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

Any help is much appreciated!

Thanks


#2

from the instructions:

Define a function search that takes a single parameter, name

your function has friends as parameter

Name will contain the name you are searching for:

var search = function(name){
     console.log(name)
} 
search("Bill")

so you can use name in your if condition


#3

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