We made a friend!


#1



I've been trying hard to figure out a syntax error that's stopping me from going forward. Please help me find the syntaxError: Expected ':' from the below code.


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(firstName, lastName, email, phoneNumber) {
    contacts[contacts.length] = {
        this.firstName: firstName,
        this.lastName: lastName,        
        this.phoneNumber: phoneNumber,
        this.email: email
    };
}

add('Venkat', 'P', 'abc@gmail.com', '(333) 000-8888');
list();


#2

The above is an object literal assignment, not a new Contact() as this would suggest. Remove this. from the property names.


#3

Thank you. That makes sense :slight_smile:


#4

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