Finding that Special Someone


#1

I don't know what I'm doing wrong, but apparently there is a syntax error. Would anyone mind helping?


SyntaxError: Unexpected token }


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);
}

var contactsLength = contacts.length;

function list() {
	for (var i = 0; i < contactsLength; i++) {
		printPerson(contacts[i]);
	}
}

/*Create a search function
then call it passing "Jones"*/

var search = function (lastName) {
    for (var i = 0; i < contactsLength; i++) {
            if (contacts[i].lastName == lastName) {
                printPerson(contacts[i]);
            } else {
                console.log ("No Contacts Found");
            }
        };
    };
};


search ("Jones");


#2

Your indentation is inconsistent, if you fix that you'll find the curly brace problem

I suggest using 4 spaces, currently you are mixing 4 spaces with tab characters or 8 spaces


#4

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