Stuck on 6/6


#1

I can't tell why my code doesn't work. When I submit, it just throws an error that says "Syntax Error: Unexpected end of input" but does not show where. I've tried reading the forums and making little changes,but nothing has worked so far. please help, I've been stuck for a week now. Thanks!

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

var search = function (lastName) {
    var contactsLength = contacts.length;
    for (var i = 0; i < contactsLength; i++) {
        if (lastName == contacts[i].lastName) {
            printPerson(contacts[i]);
        }
    };
    
var add = function (firstName, lastName, phoneNumber, email) {
    contacts[contacts.length] = {
        firstName: firstName,
        lastName: lastName,
        phoneNumber: phoneNumber,
        email: email
        }
    };

add("Mike", "Ross", "(770) 367-1234", "mikeross@pearsonspecter.com");

list();

#2

Hi,

Looks to me like your problem is in your search function.

If you look at what you've written, you have three opening curly braces ({) but only two closing braces (}).

var search = function (lastName) { //this opens your function
    var contactsLength = contacts.length;
        for (var i = 0; i < contactsLength; i++) { //this opens your for loop
            if (lastName == contacts[i].lastName) { //this opens your if statement
                printPerson(contacts[i]);
            } //this closes your if statement
        } //this closes your for loop

But you also need one to close your function.
If you correct the above to read:

 var search = function (lastName) { 
        var contactsLength = contacts.length;
            for (var i = 0; i < contactsLength; i++) {
                if (lastName == contacts[i].lastName) {
                    printPerson(contacts[i]);
                }
            }
        };

You should be ok.
Hopefully that helps you.


#3

you were correct, thanks so much!


#4

var search = function (lastName) {
var contactsLength = contacts.length;
for (var i = 0; i < contactsLength; i++) {
if (lastName == contacts[i].lastName) {
printPerson(contacts[i]);
}
};

////
Please take a look here, if (lastName == contacts[i].lastName) , it seens you forgot the syntax. It must be if (lastName === contacts[i].lastName)