Aarrrg - 6. We Made a New Friend! (Syntax Error: Invalid Shorthand...)



I really thought I was doing this right, but it's not working for me. The error message is "Syntax Error: Invalid Shorthand Property Initializer".

Can anyone help me? :frowning:

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

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

add("Ciji", "Prosser", "cprosser@example.com", "*69");



    firstName = firstName,
SyntaxError: Invalid shorthand property initializer


Exception: SyntaxError: missing : after property id


replace = with : . for example firstName: firstName,
lastName: lastName,
email: email,
phoneNumber: phoneNumber


thank you!

can you also explain to me why this "add" function doesn't need "this." before each property?

i.e. why isn't the correct syntax:

this.lastName: lastName,
this.email: email,

This wasn't part of the mistake I made - I'm just curious.


Okay as far as I can tell, in this case we have a function that takes these arguments like: function(firstName, lastName, email, phoneNumber)
so firstName and the like are all arguments that the function takes in. we cant use this.method here. Its for objects


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