Please help stuck on 6


#1


keps sayin
Oops, try again. There was a problem with your syntax.
please help


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

        }
    
    };
    var add = function(firstName,lastName,email,phoneNumber){
        var newContacts ={
            firstName : firstName,
            lastName: lastName,
            email:email,
            phoneNumber : phoneNumber
        contacts[contacts.length] = newContacts;
        };
      
    };
    search("jones");  
    add("Bob","jones", "bob.jones@example.com","(650) 777-7777"
    );
    list();


#2

this bit:

var newContacts ={
            firstName : firstName,
            lastName: lastName,
            email:email,
            phoneNumber : phoneNumber
        contacts[contacts.length] = newContacts;
        };

this line:

contacts[contacts.length] = newContacts;

should be after the }; the line below, why? because this is where you add your new contact in the contacts array, it is not part of the object you want to create

and your search function:

var search = function(lastName){

the { of the search function doesn't have a matching closing }


#3

it says It looks like there are still only two items in the contacts array.


#4

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

    }

};

};
var add = function(firstName,lastName,email,phoneNumber){
var newContacts ={
firstName : firstName,
lastName: lastName,
email:email,
phoneNumber : phoneNumber
};

}; 
contacts[contacts.length] = newContacts;
search("jones");  
add("Bob","jones", "bob.jones@example.com","(650) 777-7777"
);
list();

#5

can you post an updated version of your code?


#6

its above your message


#7

inserting the object into the array should still be part of your add function, it shouldn't part of the object you create:

var add = function(firstName,lastName,email,phoneNumber){
        var newContacts ={
            firstName : firstName,
            lastName: lastName,
            email:email,
            phoneNumber : phoneNumber
        };
       // insert object into array
}; // end of the add function

see in the comments above


#8

it worked thanks alot


#9

do you also understand why it works?


#10

yes i do understand thnaks


#11