6/8 says its correct but it looks so different than others, why?


#1

I am looking at everyone else's examples and their for/in uses 'key' even though "key" is not written in my objects..
They way I wrote it makes sense, sorta.. So why does it work with

var list = function (object) {
for (var key in object) {
console.log(key);
}
};

What I wrote came out correct but looks like this.. it makes sense to identify the 'key' as firstName instead of the generic word 'key'..

var friends = {
bill: {
firstName: "Bill",
lastName: "Gates",
number: "(602) 555-5555",
address: ['1 State street', 'Scottsdale', 'AZ', '85260']
},
steve: {
firstName: "Steve",
lastName: "Jobs",
number: "(480) 555-5555",
address: ['1 Infinate loop', 'Cupertino', 'CA', '95260']
}
};

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

}

};

list()


#2

Everything you wrote here:

[quote="mrnicholasg, post:1, topic:5600"]
var list = function (object) {    for (var key in object) {        console.log(key);    }};
[/quote]

and

[quote="mrnicholasg, post:1, topic:5600"]
var friends = {    bill: {        firstName: "Bill",        lastName: "Gates",        number: "(602) 555-5555",        address: ['1 State street', 'Scottsdale', 'AZ', '85260']        },    steve: {        firstName: "Steve",        lastName: "Jobs",        number: "(480) 555-5555",        address: ['1 Infinate loop', 'Cupertino', 'CA', '95260']        }};
[/quote]

The only part I think that makes you confused of why it is so different from others, is because of:

You actually do not need these parts, which is most likely why it looks so much different than others.

Hope it helped! :smiley:


#3

I think that the word "key" is just a placeholder so you need to replace the word "key" with an element from your object.
I did it like this:

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

I don't know if it's right for me but it tells me that it's right.

Anyway, I hope this helped you.


#4

var list = function(friends){

    for (var i in friends ){
      console.log(i); 
    };
};

#5

I got it.. thanks.. it works now