You made a friend: syntax error


#1

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

Hi All,

I am struggling with the ‘Add’ bit of this exercise. Any help much appreciated.
<Below this line, add a link to the EXACT exercise that you are stuck at.>
https://www.codecademy.com/courses/building-an-address-book/0/6?curriculum_id=506324b3a7dffd00020bf661#

<In what way does your code behave incorrectly? Include ALL error messages.>

I am getting the message: “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);
}
var add = function(firstName,lastName,email,phoneNumber) {
this.firstName: firstName,
this.lastName: lastName,
this.email: email,
this.phoneNumber: phoneNumber
}
contacts[contacts.length] = add;
add(“Joe”,“Bloggs”,"jbloggs@gmail.com";“01234567890”);
function list() {
var contactsLength = contacts.length;
for (var i = 0; i < contactsLength; i+=1) {
printPerson(contacts[i]);
}
}
list();

<do not remove the three backticks above>

#2

For starters, where is your "search"function>?


#3

Hi Kat

I deleted the search function as suggested in the instructions, as I didn’t think I needed it to make the ‘Add’ function work?

Thanks
Joe.


#4

Wrong search function, The search function they wanted you to delete was the search(“Jones”); one. Not the huge search function. Without it, the program will not function properly.


#5

Oops, my bad.

I’ve added it back in but I’m still getting “SyntaxError: Unexpected token :”

Is there anything else that you can see might be wrong?

Thanks again, Joe.


#6

Hi Joe,

I did the same thing as you did using the THIS keyword on my first try, and it didn’t work.

var add = function (firstName,lastName,email,phoneNumber) {

// #1. Make a new object to hold the values WITHIN the function
var newContact = new Object();
newContact.firstName = firstName;
newContact.lastName = lastName;
newContact.email = email;
newContact.phoneNumber = phoneNumber;

// #2. Add the new object to the array – also WITHIN the function
contacts[contacts.length]= newContact;
}

// 3. Now each time you call the function, it will create new object and add it to the array
add(“Eddie”,“Murphy”,"em@me.com",“333-4578”);
list();


#7

hi guys! I found the instructions for this portion quite unclear but this is what I came up with. I think this is what they wanted. seems to work ???

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


#8

you actually do not need the search function for this section to work. i deleted the entire function as well