0

I am trying to return contact info for "steve", but codecademy is telling me that it is not returning correctly.

It looks like your search function doesn't return contact information for Steve.

I am not able to find any error in this code. Can you help me with finding any syntax or logical errors in the search function that you can see?

var friends = {
    bill: {
        firstName: "bill",
        lastName: "gates",
        number :21415,
        address: ["mcklsn", "wcnskln"]
    },
    Steve: {
        firstName: "bill",
        lastName: "gates",
        number: 21415,
        address: ["mcklsn", "wcnskln"]
    }
};

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

    for (steve in friends)
        console.log(steve);
};

var search = function(name)
{
    for (var i in friends)
    {
        if (friends[i].firstName === name)
        {
            console.log(friends[i]);
            return friends[i];
        }
        else
            console.log("contact doesn't exist!");
    } 
};
5
  • What exactly is the problem? Commented Jan 18, 2016 at 15:20
  • @Idos the compiler is saying "It looks like your search function doesn't return contact information for Steve.". really dn't know how to fix it?! Commented Jan 18, 2016 at 15:25
  • @Idos well i am learning js in codecademy and the error is shown exactly like this. it's unedited. Commented Jan 18, 2016 at 15:30
  • @DanLowe how to make it into an array? Commented Jan 18, 2016 at 15:31
  • please accept the answer if it solved your question (by clicking the green check mark next to it). Commented Jan 21, 2016 at 8:19

2 Answers 2

1

You should really pay attention to what you are writing, don't Ctrl-C Ctrl-V everything blindly. You are not calling your friends in the correct names and I would be offended if someone did that to me. Heck, Steve Jobs would be furious if you called him Bill!

This should work:

var friends = {
    Bill: {
        firstName: "Bill",
        lastName: "Gates",
        number: 21415,
        address: ["mcklsn", "wcnskln"]
    },
    Steve: {
        firstName: "Steve",
        lastName: "Jobs",
        number: 21416,
        address: ["mcklsnn", "wcnsklnn"]
    }
};

search("Bill");
search("Steve");
Sign up to request clarification or add additional context in comments.

Comments

0

Yah, because your Steve property object's firstName is set to "bill".

So that code, searching for a match to 'steve' on the firstName property will not find one...because there isn't one. Both of those object's have 'bill' as their firstName property.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.