6. I got it right but "Bill" does not print


#1

var friends = new Object();
friends.bill = new Object();
friends.steve = new Object();

var friends = {
bill: {
firstName: "Bill",
lastName: "Gates",
number: "1232345",
address: ['One Micro Town', 'Red street']
}
};
var friends = {
steve: {
firstName: "Steve",
lastName: "Jobs",
number: "19852913",
address: ['Pillow Town', 'Pink Street']
}
};

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

//prints out
steve
{}

can someone explain?


#2

i understood my mistake and fixed it.


#3

I'm a noob too and only passed this a few days ago but I'll try to help. Forgive me if I make mistakes.
I've spotted a few problems

Firstly you have unnecessary code.

var friends = new Object();
friends.bill = new Object();
var friends = {
bill: {
}
};

You created the objects using new Object Constructors, then used literal notation to do the same thing again.
Don't worry too much about this problem, the coming lessons will elaborate and help you better use each.
Just use one of them.

=======

Next, I could be wrong on this. I think you might be overwriting your object. You created it, filled it with bill, then overwrite it with steve.
If you're using the literal notation, put both of them in at the same time. They'll be separated by the opening and closing curly braces within the friends object.

=======

Next, the most confusing part of this particular exercise. The "for in" loop.
Basically, the list function is simply to list all the properties in an Object, any object.

This code is too specific and is the fault of the hint.

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

THE CODE COULD BE:
var list = function (gotham) {
for (var batman in gotham) {
console.log(batman)
}
};

You're not trying to find your properties in your object with this function. You're creating a function to search any stated object, for any properties it has.

====

Hope I've not confused you more. And if I've made any mistakes, someone please please correct me.