A function?


#1

The error i am getting is that the function list has not been created. Seems weird. Can someone please help?

var friends = {
bill: {
address: ['1 Microsoft drive','32 Mclean drive']
},
steve: {
address: ['1 Infinite Loop']
}
};
friends.bill.firstName = "Bill";
friends.steve.firstName = "Steve";
friends.bill.lastName = "Gates";
friends.steve.lastName = "Jobs";
friends.bill.number = "0 986 764 6343";
friends.steve.number = "+1 983 363 7777";

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


#2

the FUNCTION talk

var myFunc = function( param1, param2) {
       //Begin of  anonymous FUNCTION-BODY
       //VARIABLE -myFunc- has an -anonymous function- assigned
       //this -anonymous function- has 2 PARAMETERS param1 and param2
       //param1 and param2 PARAMETERS are used 
       //as -local- VARIABLES throughout the FUNCTION-BODY

      console.log( param1 + " and " + param2 ) ;

      //End of anonymous FUNCTION-BODY
};

If you want to call/execute the anonymous function
you will have to add a pair of parentheses to the variable myFunc
like
myFunc();
As the anonymous function was defined
as having 2 parameters
you have to provide 2 arguments
in our case 2 string VALUES "Alena" and "Lauren"
like
myFunc("Alena","Lauren");

some quotes from the outer-world:

**argument is the value/variable/reference being passed in,
parameter is the receiving variable used within the function/block**

OR

**"parameters" are called "formal parameters",
while "arguments" are called "actual parameters".**


#3

+++++ nyc object and the for-in loop explained ++++++++++++++++

T h e - B a s i c s

An object has one or more properties seperated by a comma-,
Each property consists of a property-key and it's associated VALUE

var nyc = {
       fullName: "New York City",
       mayor: "Bill de Blasio",
       population: 8000000,
       boroughs: 5
      };
nyc -object- S p e c i f i e d

The nyc object has 4 properties seperated by a comma-,
- a fullName property with property-key fullName and it's associated string value of "New York City"
- a mayor property with property-key mayor and it's associated string value of "Bill de Blasio"
- a population property with property-key population and it's associated number value 8000000
- a boroughs property with property-key boroughs and it's associated number value 5

for - in - loop - e x p l a i n e d

With the for-in-loop you have a Method
which will iterate over all properties of a given object.
At each iteration it will assign the property-key as a string
to a variable name of your choice.
Thus for (var x in nyc)
will lead to 4 iteration's
iteration-1 var x = "fullName";
iteration-2 var x = "mayor";
iteration-3 var x = "population";
iteration-4 var x = "boroughs";
As they want you to display the property-key and NOT it's associated VALUE
you would use
console.log( x );

If they wanted you to display the associated VALUE of the propery-key you would use
console.log( nyc[x] );


#4

@cshikhar,

Your list function

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

As the list function is defined as having 1 parameter friend
( which is used as a =local= variable throughout the FUNCTION-BODY )
and as you want to call / execute the list function
you will have to provide 1 argument which should have an object Value
in our case the variable friends
like
list(friends);