List 'em all! //Help please!


#1

Hello! I keep receiving an error message that states "Did you create a function called list?"

I'm fairly certain I have. I believe there may be something wrong with my for/in syntax. Can someone help me?

friends = new Object();

friends.bill = new Object();
    friends.bill.firstName = "Bill"
    friends.bill.lastName = "Gates"
    friends.bill.number = "(555) 555-5555"
    friends.bill.address = ['1 Tech Way', 'Ozark', 'AL', '36360']
friends.steve = new Object();
    friends.steve.firstName = "Steve"
    friends.steve.lastName = "Jobs"
    friends.steve.number = "(555) 555-5555"
    friends.steve.address = ['1 Tech Way', 'Ozark', 'AL', '36360']
    
var list = function (friends) {
    for (var key in friends) {
        console.log(bill)
        console.log(steve)
    }
}

#2

Why build a loop, and the manually log bill and steve to the console? Use the loop to log the right data


#3

Okay. So perhaps I should log the object friends then? I've tried that and I'm still not executing the code correctly. Can you provide some more insight?


#4

I've got it! I must log key. It makes sense now.


#5

good, that you made it work :slight_smile: And that it makes sense, more important


#6

Well, actually. I'm still not sure I understand. I thought the whole point was to log each contact's information to the console. All that was logged was

bill
steve
["1 Tech Way","Ozark","AL","36360"]


#7

this line is just logged by console behavior, it always logs the last value. So your understanding is correct


#8

Yes, I understand now. I did not realize there was more to the code. I'm working on the next lesson now. Thank you!


#9

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