Displaying People


#1

Just wanna know if my code is correct, although it checked correct

var bob = {
    firstName: "Bob",
    lastName: "Jones",
    phoneNumber: "(650) 777-7777",
    email: "bob.jones@example.com"
};

var mary = {
    firstName: "Mary",
    lastName: "Johnson",
    phoneNumber: "(650) 888-8888",
    email: "mary.johnson@example.com"
};

var contacts = [bob, mary];

// printPerson added here
var printPerson = function (person) {
    console.log(bob.firstName + " " + bob.lastName);
    console.log(mary.firstName + " " + mary.lastName);
    }
    
printPerson(contacts[0]);

#2

No it is not correct.

Try to call your printPerson function like this.

printPerson(contacts[11]); // There is no twelth object

You didnt get an error but you print the right things.

And what is if you a third object(Person)?


#3

The function is used to make our life easier and that we do not have to write the same code twice if we only change a small bit of it, for example only a name.

Right now you do not take advantage of the function properties. The function is not dynamic, does not matter what you pass through the argument it will always be outputting bob and mary.

Change the body of the function so that it will be a dynamic. When you pass through bob, then it will display bobs firstname and lastname. If you pass through mary, then it will display marys first and lastname


#4

@medohamdani,

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".**


#5

Okay, that's why it just passed. Thanks