6. We Made a Friend!


#1



link


I have the error 'SyntaxError: Unexpected identifier' and have no idea what's wrong :\

Thank you if someone can point out the problem!


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 (i=0;i<contactsLength;i++) {
        if (contacts[i].lastName = lastName) {
            printPerson(contacts[i]);
        }
        else {
            console.log("");
        };
    };
};
search("Jones");

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

add("Osama","Binladen","OB.c@gmail.af","9112001");


#2

i see two problems, in your add function:

lastName lastName,

oops, missing colon after lastName:

lastName: lastName,

does that require a explanation?

The second mistake, is in this line:

if (contacts[i].lastName = lastName)

using a single equal sign means assign, if conditions are generally used to compare (two equal signs)


#3

Works now! Thanks (;