Error when trying to complete exercise


#1


I am trying to figure out what is wrong with my code in exercise 6 of the Contact List:


https://www.codecademy.com/courses/javascript-beginner-en-3bmfN/0/6?curriculum_id=506324b3a7dffd00020bf661#


The error I get is :
Oops, try again. Did you create a function called list?


var friends = {
    bill: {
        firstName: "Bill",
        lastName: "Gates",
        number: "(206) 555-5555",
        address: ['One Microsoft Way', 'Redmond', 'WA', '98052']
        },
    steve: {
        firstName: "Steve",
        lastName: "Jobs",
        number: "(555) 555-5555",
        address: ['One Apple Way', 'Redmond', 'WA', '98052']
        }
};

var list = function (friends) {
    for (var key in object) {
        console.log(friends[firstName]);
        console.log(friends[lastName]);
        console.log(friends[number]);
        console.log(friends[address]);
    }
};


#2

your function code is wrong.
your function should change by this:

var list = function (friend) {
    for (var i in friend) {
        console.log(i);
    }
};

attention to instructions: For example, if you only have bill and steve as entries, list should just print out "bill" and "steve"

you should print the key value of that object, bill and steve are key's of friends, firstName, lastName, number, address are key's of bill or steve.
any object have own special key.


#3

Okay, that sort of makes sense, but where does i come from? How does it know what i is? I implemented your suggested changes and am getting the same message, so I must be missing something else.

var friends = {
    bill: {
        firstName: "Bill",
        lastName: "Gates",
        number: "(206) 555-5555",
        address: ['One Microsoft Way', 'Redmond', 'WA', '98052']
        },
    steve: {
        firstName: "Steve",
        lastName: "Jobs",
        number: "(555) 555-5555",
        address: ['One Apple Way', 'Redmond', 'WA', '98052']
        }
};

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

#4

Never mind, found it. Thank you!


#5

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