6. List 'em all!



The instructions for this module ask to print out "bill" and "steve". However, the interpreter keeps displaying the details for steve. How do I modify my code so the interpreter stops printing out all the details for steve?

{"firstName":"Steve","lastName":"Hangy","number":"908-745-4123","address":["4810 Langley Drive","Alto Palo","CA","91820"]}

var friends = {};
friends.bill = {
    firstName: 'Bill',
    lastName: 'Madison',
    number: "123-456-7890",
    address: ['9182 Williams Rd', 'San Antonio', 'TX', '78291']
friends.steve = {
    firstName: 'Steve',
    lastName: 'Hangy',
    number: "908-745-4123",
    address: ['4810 Langley Drive', 'Alto Palo', 'CA', '91820']

var list = function(friends) {
    for (var key in friends) {


Did you call the function?



Hey Denys,

I didn't call the function. When I added list(friends); I am getting



question: Adding the function call should allow you to pass the exercise, did you pass?

The exercise also calls your function (it needs to validate your function works correctly), because your function has a console.log, this function call will also log output, don't worry about it


Adding the function call did let me pass the exercise.

Okay, that makes sense. Thank you!


Do you understand everything or do you still have questions?


We created a function called list, which looks for the primary keys in object using the for/in loop.

It doesn't look for secondary keys (like firstName, lastName, number or address).

To display bill and steve, I needed to call the list function.

Is that right?


yep, and the keys (what you call primary keys) of friends object are bill and steve. (not to confuse with "Bill" and "Steve" which are the values of firstName key)

firstName (and so on) are keys of bill and steve. Your for in loop only looks for the keys of friends (the keys of friends are bill and steve)

a function only executes when called, so yes :slight_smile:


Great explanation. I also read your answer to https://discuss.codecademy.com/t/7-search-for-a-friend-its-hard-to-understand/74290/3

I have a much better understanding of how this works.

Friends (object) have 2 keys: bill and steve.

bill and steve are objects themselves, and have the keys: firstName, lastName, number, and address)

Because we are calling keys in friends object, list(friends) will display bill and steve when called on.

Thank you Stetim!


Seems you understanding has improved a lot :slight_smile: Now you can move on :slight_smile:


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