Stuck and I don't know what's wrong. 6/6


#1

I have checked through this several times and I was close to finishing but something happened when I exited codecademy It gives me this when I run it "ReferenceError: lastName is not defined" What am I doing wrong?
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, contacts];

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

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

/*Create a search function
then call it passing "Jones"*/
function search(lastname) {
var contactsLength = contacts.length;
for(var i = 0; i < contactsLength; i++) {
if(lastName === contacts[i].lastName){
printPerson(contacts[i]);
}
}
}
add("Ichigo", "Kurosaki", "(650) 999-9999", "Ichigo@SoulReaper.com");
search("Kurosaki");
Anybody that can help with this I will be very happy with. Please help me!


#2

@kelohec,
You have 2 problems.

-1

Change your contacts[]-Array definition
from

var contacts = [bob, mary, contacts];

into

var contacts = [bob, mary];

-2

In the definition of your **search-=function=
you will have to change the parameter lastname into lastName

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

#3

I fixed those problems but now it gives me ReferenceError: array is not defined. WHAT AM I DOING WRONG. Here is a updated version.var bob = {
firstName: "Bob",
lastName: "Jones",
phoneNumber: "(650) 777-7777",
email: "bob.jones@example.com"
}

var mary = {
firstName: "Mary",
lastName: "Johnson",
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]);
}
}

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

/*Create a search function
then call it passing "Jones"*/
function search(lastName) {
var contactsLength = contacts.length;
for(var i = 0; i < contactsLength; i++) {
if(lastName === contacts[i].lastName){
printPerson(contacts[i]);
}
}
}
add("Ichigo", "Kurosaki", "(650) 999-9999", "Ichigo@SoulReaper.com");
search("Kurosaki");
I need all the help I can get because I have no idea what is wrong.
Thanks.


#4

@kelohec,

Change your

array[array.length]

into

 contacts[array.length]

=============================================

Your mary object is missing a property....


#5

Thank you for helping me. I hope I did not waste to much of your time.


#6

You didn't waste my time! Thanks for asking your questions so I could see the flow of the code!