6 make new friends person not defined


#1

i this is my code is , the that appears is " You have the following error in your code: TypeError: person is undefined "

my code is this

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 j = 0; j < contactsLength; j++)
{
if (contacts[j].lastName === lastName)
{
printPerson(contacts[j]);
}
}
};

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

add ("Ze", "Carlos" , "271336739","carlos@mail.com");
list();

if anyone can help me i would thank a lot :slight_smile:


#2

Your mistake is in function for --> should be "i < contactsLength", not <=
just remove "="


#3

thank's a lot it worked :slight_smile:
in the previous exercises , the <= was acepted why ??
but thanks anyway.


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.