6/6 Missing before statement


#1

Hey Everybody,

I can't figure out what's wrong with my code. The error I get is: SyntaxError: missing before statement. Any help would be appreciated, thanks.

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]);
}
}

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

add("Davie", "Crocket", "999-999-999", "dc@example.com");
list();


#2

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]);
}
}

function add(firsName, lastName, phoneNumber, email) {
contacts[contacts.length] = { <------------remove the "new contact" & "firstname" above your <----------------------------------------------------------------parameter wasn't spelt correctly:
firstName: firstName,
lastName: lastName,
phoneNumber: phoneNumber,
email: email,
}
};

add("Davie", "Crocket", "999-999-999", "dc@example.com");
list();

Hope this works..you'll need to remove newContact, because you don't need to name your object,
you'll access its value through the array.


#3

Thanks, that helped.

I had actually added "newContact" when I was trying to figure out what was wrong because I saw it in another thread but I totally missed the spelling error in the parameters though.