6/6 We Made a Friend! Getting error message new entry being logged


#1

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>
https://www.codecademy.com/courses/building-an-address-book/0/6?curriculum_id=506324b3a7dffd00020bf661

<In what way does your code behave incorrectly? Include ALL error messages.>
My error is:
TypeError: Cannot read property ‘firstName’ of undefined

The new entry I created (The Dude) logs under Bob and Mary, but I still get this error.

```

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];

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

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

/Create a search function
then call it passing “Jones”
/
var search = function(lastName){
var contactsLength = contacts.length;
for(var i = 0; i < contacts.length; i++){
if (lastName === contacts[i].lastName){
printPerson(contacts[i]);
}
}
};
search();

function add(firstName, lastName, email, phoneNumber){
contacts[contacts.length]= {
firstName: firstName,
lastName: lastName,
email: email,
phoneNumber: phoneNumber
};

};
add(“The”, “Dude”, "email@email.com", “(555)100-2000”);
list();

<do not remove the three backticks above>

#2

@bealearnscode1,
-1
In your list() function
you should change your FOR-loop condition

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

into

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

-2
Your search() function call needs an argument like
search(“Jones”);

-3
I would expand the =last= list() function call with
2 lines of code like

list();
console.log( "== My End ==" );
console.log( "== All that is displayed now, is the course-checker ==" );