6. We Made A Friend!


Error Message: SyntaxError: Unexpected token :

I've gone through several topics to find the answer...I'm still stuck

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++) {

/*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 (contacts[i].lastName === lastName) {


function add(firstName, lastName, email, phoneNumber) {
    firstName: firstName,
    lastName: lastName,
    email: email,
    phoneNumber: phoneNumber




Your problem is right here. I assume you're trying to create a function that creates new object.

Try something like this:

var Person = function(firstName, lastName, phoneNumber, email){
  this.firstName = firstName;
  this.lastName = lastName;
  this.phoneNumber = phoneNumber;
  this.email = email;
var bob = new Person("Bob", "Jones", "(650) 777-7777", "bob.jones@example.com");

var mary = new Person("Mary", "Johnson", "(650) 888-8888", "mary.johnson@example.com");

Now everytime you will use "new Person(...)", it will be like using the function you tried to make.

Also, if you want to add these objects into array, use:

var contacts = [];

push() is a method of Array object. It pushes anything(ex. Object) into array. Therefore contacts[0] is now object mary and contacts[1] is object bob.


It worked in the original syntax in earlier lessons, i guess it doesn't want that now


The problem starts in this line. Already told you why :slight_smile:


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