6. We made a friend!


#1

Can someone help me find the problem in this code?

Here it is:

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]);
}
}
/Create a search function
then call it passing "Jones"/

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

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

}

add("Hans", "Moleman", "HolyMoley@Smail.com", "(555) 555 - 1234");
list();

}

add("Hans", "Moleman", "HolyMoley@Smail.com", "(555) 555 - 1234");
list();


#2

Nevermind I fixed the problem!!!


#3

Uncaught SyntaxError: Invalid regular expression: missing /

You are missing an extra / in your comment "/Create a search function"

// A single line comment is made using two forward slash characters