We Made a Friend - syntax help


#1

Can anyone spot the error? Thanks in advance for your help!

ERROR: Oops, try again. There was a problem with your syntax.


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 search(lastName) {
    var contactsLength = contacts.length;
    for (var i = 0; i < contactsLength; i++) {
        if (lastName ===  contacts[i].lastName) {
            printPerson(contacts[i]);
        }}
};

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

add("Ami", "Eliz", "a.e@example.com", "5756412598");


#2

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

property-key and property-value should be separated by a colon(:) instead of =


#3

You have function add(firstName, lastName, email, phoneNumber) {...........
while the sequence should be firstName,lastName, phoneNumber,email

my code works and it is given below

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


#4

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