Code not working


#1

Hi,
I don't understand why the following message keeps popping up:
"Oops, try again. It looks like your search function doesn't return contact information for Steve.".
I have worked on this for many hours. Can someone see where the mistake is? Thank you!

var friends = {
bill: {
firstName: "bill",
lastName: "Bill",
number: "123-456-7891",
address: ['Three Coffee Lane', 'Rancho Viejo', 'CA', '33098']
},
steve: {
firstName: "steve",
lastName: "Steve",
number: "345-678-9123",
address: ['Two Gosship Circle', 'Jackson', 'NY', '86724']
},
};
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];
        }
    }
};

#2

Your for statements should be for (key in friends){ rather than for (var key in friends){ and it appears to be working to me on repl.it, but I can't find that exact lesson on Codecademy. The one I did was different.


#3

Hi Dantemp,
Thanks so much for responding. This is lesson 14-7 entitled: Search for a friend. There are 2 cases of "for (var key in friends){ and per your instructions I tried all combinations of using/omitting var. Unfortunately I still get the same error message above.


#4

@ballewh1 I apologize for confusing you, inconveniencing you, and wasting some of your time. After looking at it some more, I discovered that the problem was not with your function, but rather with your object. You need to capitalize the first letter in both first names, like so, firstName: "Bill", rather than firstName: "bill".


#5

Adding to @dantemp point, can you format your code please? This should help on that... Thankyou


#6

Thanks very much Dantemp! That worked. What is the reason for that?


#7

It was looking for something with a firstName assigned to "Steve" rather than "steve"