Syntax error var! help needed!Thanks a lot!


#1



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


SyntaxError: Unexpected token var


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

function search(lastName){
    contacts[contacts.length] = {
    for (var i = 0; i < contactsLength; i++){
        if (contacts[i].lastName ===lastName){
            printPerson(contacts[i]);
        }
        else{
            console.log (" ")
        };
    }
};


function add(firstName,lastName,phone,Numberemail){
    contacts[contacts.length] = {
        firstName: firstName,
        lastName: lastName,
        phoneNumber: phoneNumber,
        email: email
    }
};
add ("Sherry","Xue","123456789","sherry@gmail.com")
list();


#2

@devace71301,

function search(lastName){
//    contacts[contacts.length] = {
    var contactsLength =contacts.length 
    for (var i = 0; i < contactsLength; i++){
        if (contacts[i].lastName ===lastName){
            printPerson(contacts[i]);
        }
        ///else{
        ///    console.log (" ")
        ///};
    }
};

#3

It worked, thank you so much! Could you please tell me why?


#4

Is it because that I have the same line in the add function so I skip it here?


#5

Oops! I typed "phone,Numberemail" instead of "phoneNumber,email"