Help Absolutely lost,


#1

whats i do

Replace this line with your 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 add];

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 kop = contacts.length;  
  for (var i = 0; i < kop; i++) {
	if(contacts[i].lastName === lastName){
	  printPerson(contacts[i]);
	 }
	}
};
search(bob.lastName);


var add = function (fistName, lastName, email,phoneNumber) {
var newContact = {
firstName: firstName,
lastName: lastName,
email: email,
phoneNumber: phoneNumber     
 }

};



add();


#3

That is a pretty good code.

But to add a new friend to the contacts you need to add something to the add function. This is not the correct way:

var contacts = [bob, mary add];

You can use method push or just assign new value to the contacts[contacts.length].

And in the function call (add()) it would be nice to pass some data.


So, change the contacts to the original form:

var contacts = [bob, mary];

Tweak your function to add new contact to the contacts (there is also a typo, firstName, not fistName):

var add = function(firstName, lastName, email, phoneNumber) {
    var newContact = {
        firstName: firstName,
        lastName: lastName,
        email: email,
        phoneNumber: phoneNumber
    };
    contacts.push(newContact);
};

And call your function with some data and list all the contacts:

add("Maciej", "Wiercioch", "wiercioch@outlook.com", "607034771");
list();

#4

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