We made a friend- find out the error in searching if u can


#1


https://www.codecademy.com/courses/building-an-address-book/0/6?curriculum_id=506324b3a7dffd00020bf661

Oops, try again.
It looks like there are still only two items in the contacts array.


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

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)
{
        for (var i = 0; i < contacts.length; i++)
        {
            if(contacts[i].lastName==="lastName")
            {
                
            
        printPerson(contacts[i]);
            }
    }
}
 var add = function(firstName,lastName,phoneNumber,email){
contacts[contacts.length] = {
firstName: firstName,
lastName: lastName,
phoneNumber: phoneNumber,
email: email
}

}
list();
add("venkat","prsad",999596,"mkom");
search("Jones");


#2

Try calling list() after you add the other contacts.


#3

Move the list() after the add function.


#4

@designace62460,

var contacts = [bob, mary,venkat]; // remove venkat
  1. venkat is not defined. You need add the 3d contact venkat using function add.
  2. Error in search function:

if(contacts[i].lastName==="lastName"); // try contacts[i].lastName===lastName

Move list(); to the last line or as said @tekkie1618 and @rubyjumper00998.


#5

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