We made a friend



Please please help me, I've been staring at this code for a really long time now, comparing to other codes as well and I just can't see what's wrong in there. I get the "Oops, try again. It looks like there are still only two items in the contacts array." message and don't know why.

Thanks for your help!

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++) {

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

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

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

add("James", "Brown", "(456) 245-245", "brownie@gmail.com");


TypeError: printPerson.contacts is undefined

Check your list function for the proper usage.

ReferenceError: contact is not defined

Since you have already made the assignment in the previous line, this line is superfluous and actually attempts to add an undefined object to the last element. This raised an exception which the SCT interpreted within its range of possible messages.


Ok, thanks a lot, I got it!


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