We made a friend


#1


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


I AM GETTING A SYNTAX ERROR, WHAT IS WRONG WITH MY CODE?
SyntaxError: Invalid or unexpected token


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

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

search('Jones');
    
console.log(contacts.length);    

function add(firstName, lastName, email, phoneNumber){
contacts[contacts.length] = new Object(John);
    
    firstName = 'John';
    lastName = 'Smith';
    phoneNumber = "(222) 222 - 2222';
    email = 'john.boy@gmail.com';
}


#2

You used assign operator = but here you need to use comparison operator ===.

Function add() takes parameters for defining properties. Also new Object() doesn't have any parameters.
We can create new object using literal notation or constructor notation. But instructions says:

Do it like this:

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

#3

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