6. We Made a Friend syntax error


#1


Stuck on this, please help!

I think the lines in question are at the bottom, the "add" function.
I keep getting the same syntax error message: "expected : ".
I don't know where this " : " is expected to be.
And you can comment on the "new" keyword I used before "contacts" in the add function, but I've tried it both with and without and neither works.

Where is my syntax error?

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


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


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

search("Jones");

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

add ("Chris","Smith","(555)-555-1212","chris.smith@example.com");

list();


#2

remove new and this from your add function.


#3

That worked! Thank you.


#4

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