My code works and I dont understand why


I get confused after the if statement. I changed my code 5 times before I got it to work.

Why does it have to be printPerson(bob)

why can't it be printPerson(lastName) ?

var bob = {
firstName: "Bob",
lastName: "Jones",
phoneNumber: "(650) 777-7777",
email: ""

var mary = {
    firstName: "Mary",
    lastName: "Johnson",
    phoneNumber: "(650) 888-8888",
    email: ""

var contacts = [bob, mary];

function printPerson(person) {
    console.log(person.firstName + " " + person.lastName);

function list() {
	var contactsLength = contacts.length;
	for (var i = 0; i < contactsLength; i++) {

/*Create a search function
then call it passing "Jones"*/
var search = function(lastName){

    var contactsLength = contacts.length;

    for (var i = 0; i < contactsLength; i++){

        if (contacts[i].lastName == lastName){



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

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


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


console.log( contacts );
would have revealed that you have created an Array with 2 elements
and each of those elements is an object

[ { firstName: 'Bob',
    lastName: 'Jones',
    phoneNumber: '(650) 777-7777',
    email: '' },
  { firstName: 'Mary',
    lastName: 'Johnson',
    phoneNumber: '(650) 888-8888',
    email: '' } ]

console.log( contacts[0].firstName ); ==>output>> Bob
console.log( contacts[1].email ); ==>output>> ''
console.log( contacts[1] ); ==>>output>> the Mary-Object

As your printPerson function takes 1 parameter person
the printPerson function will expect 1 argument being the contacts[i] object
which you have just found by comparing contacts[i].lastName with the search argument 'Jones'.

It might be that you get a double-output,
as the course-checker also has it's output in your Display.
Add following line to the end-of-code.....
console.log( "This the END-of-my-CODE" );
and you will be able to see what is yours and what is the =code-checker=.