6. We Made a Friend! Unexpected token [


#1

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

I keep getting the errormessage: Oops, try again. There was a problem with your syntax.
In the consol it says: SyntaxError: Unexpected token [

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

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

add("Johanna", "Palmkvist", "(070) 387-3774", "johanna.palmkvist@home.com");

list();

#2

Hi this part

var contacts[contacts.length]

you should remove the var


#3

I tried, it now says SyntaxError: Unexpected identifier in the console :s


#4

then here you should add a , after phoneNumber: phoneNumber

        lastName: lastName,
        phoneNumber: phoneNumber
        email: email
    };

#5

It works! Thanks for the help :slight_smile: