What's wrong with my code?


#1

var friends = {
bill:{
firstName: "Bill",
lastName: "Johson",
number: "09157757865",
address: ['One Microsoft Way','Redmond','WA','98052']
},
Steve: {
firstName: "Steve",
lastName: "Rock",
number: "09157735461",
address: ['Bonaficio','taguig','manila','98602']
}
};
var list = function (friends){
for(var firstName in object){
console.log("Printing a string");
var myString= "bill";
console.log(myString);
}
};


#2

The for/in statement loops through the properties of an object.The block of code inside the loop will be executed once for each property.

syntax:

for (var prop in object) {
code block to be executed
}

The "prop" bit can be any placeholder name you like. It's sort of like when you put a placeholder parameter name in a function that takes arguments.
how it works
you have taken

for(var firstName in object)

here firstName is just a name of a variable. it doesn't mean its the firstname of an object.and here object name must be
friends.loop through the friends object.
run this code

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

instead of

var list = function (friends){
for(var firstName in object){
console.log("Printing a string");
var myString= "bill";
console.log(myString);
}
};

run this too

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

and

var list = function(){
for(var p in friends){
console.log(p);
//console.log(friends[p]); //uncomment this
}
};
list();

to know more click here