We made a friend


#1

what's wrong about my code..?

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

        }
    
    }
};

var add = function (firstName,lastName,phoneNumber,email)
    {
        contacts[contacts.length] = {
            firstName : firstName,
            lastName : lastName,
            phoneNumber : phoneNumber,
            email :email
        }
        
};
list();
 add("mahmud","ph","mahmudie@gmail.com",284230);
search("Jones");

#2

i think the error message pretty much covers it:

Did you remember to call list() after adding your new contact?

you call the list function before adding contact, so the new contact isn't logged to console


#3

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