6. List 'em all


#1



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


Oops, try again. It looks like your list function isn't printing the right output.


var friends = new Object();
    friends.bill = new Object();
        friends.bill.firstName = 'Bill';
        friends.bill.lastName = 'Gates';
        friends.bill.number = '(206) 555-5555';
        friends.bill.address = ['West str', 'South str'];
    friends.steve = new Object();
        friends.steve.firstName = 'Steve';
        friends.steve.lastName = 'Jobs';
        friends.steve.number = '(206) 666-6666';
        friends.steve.address = ['North str', 'East str'];
        
var list = function(friends) {
    
    for(var bill in friends) {
        console.log(friends[bill].firstName + " " + friends[bill]   .lastName + ": " + friends[bill].number  + ": " + friends[bill].address);
        }
        
    for(var steve in friends) {
        console.log(friends[steve].firstName + " " + friends[steve] .lastName + ": " + friends[steve].number + ": " + friends[steve].address);
        }
    
    };

list ();


#2

This is not necessary. The reason you're using a for loop was to avoid what you've done. To print out bill and steve just use the basic for loop format for printing out items in a list or dictionary.

for (var key in friends) {
    console.log(key)
}

#3

Thanks for this, works fine now.


#4

You're welcome. :slight_smile:


#5

This helped me as well. Thank you!


#6

i just dont understand how that function grab only first names from array. Why not adress or last name? Could you please explain or give me some link for that?


#8

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