6/6 ReferenceError: array is not defined


#1

I have no idea why this is not working. I have reread my code and the instructions several times, so please don't respond with "Durr, you forget the ______ you big dummy." Here is my code, again what is 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];

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


#3

RESEARCH COMPLETED!!

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

Alright, this one is kind of a "You have to look at the hint if you don't know what's going on" scenario. It's unfortunate but that's just a part of coding.

Alright, so basically what the lesson is trying to get you to do is give the "function add" an object that can effect arrays.. SIMPLE!! Oh wait, no it's not.. BUT THAT'S WHY I'M HERE!! :smiley:

So the example in the white description field it shows something along the lines of what you have above. So I know you're reading and trying hard at it, unfortunately that was just an example, and what it wanted you to do is almost exactly opposite of that.

Really it wants you to make an Object, "which I called handsome because that's what I am!" and then AFTER the object it wants you to then add the Object to the array.

"Kool LoLMaN, so what? that means nothing to me!" - You say in anger and disgust. "Have no fear" I reply, because it does mean something!

function add(firstName, lastName, email, phoneNumber) {
	
	var handsome = { //being handsome is a job that I must do!
			firstName: firstName,
			lastName: lastName,
			email: email,
			phoneNumber: phoneNumber
	};
	contacts[contacts.length] = handsome; /* I'm going to add handsome to the
contacts array! */
}

You had the right idea, but in the wrong order. Just note that as the lessons get harder it will start making you think of your own solutions to problems instead of actually giving them to you. UNFORTUNATE.. but necessary for growth!

ALSO

Just one small little thing!

" ; " <-------

Take those off the end of your functions!