6.We Made a Friend!


#1



The error says: "It looks like you didn't log "Beyonce Jasmine" to the console. Did you remember to call list() after adding your new contact?"

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 < contacts.Length; i++) {
printPerson(contacts[i]);
}
}

/*Create a search function
then call it passing "Jones"*/

var search = function(lastName) {
var contactsLength = contacts.length;
for(var i=0; i{
if(contacts[i].lastName === lastName)
{
printPerson(contacts[i]);
}
else
{
"something went wrong";
};
};
}

search("Jones");

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

add("Beyonce","Jasmine","BJ.chese@gmail.com","415510408");

list();


Replace this line with your code.


#2

for(var i=0; i{
if(contacts[i].lastName === lastName)

i think its your copy-paste mistake!!!paste correctly so we can help you :slight_smile:


#3

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"*/
function search(lastNames){
var contactsLength = contacts.length;
for (var i = 0; i < contactsLength; i++) {
if(contacts[i].lastName == lastNames){
printPerson(contacts[i]);
}
}
}

//search("Jones");

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

var krishna = add("Krishna","Kumar","Krishna.Kumar@Example.com","123456789");

list();


#4

i found for the function its more efficient to say:

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

add("Mr.","contact","person@website.com","1234567890");

list();


#5

@dedlupid,
Have a read to get knowledge about the difference
http://stackoverflow.com/questions/336859/var-functionname-function-vs-function-functionname?rq=1