6. We Made a Friend! - stuck and need help!


#1


I don't know what I've done wrong! Can anyone help please?? I keep getting an error message of 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);
}

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"*/
function search(lastName) {
    for (j = 0; j < contacts.length; j++){
    if (contacts[j].lastName === lastName){
     printPerson(contacts[j]);
    }
    }
}
search('Jones');
      
function add(firstName, lastName, email, phoneNumber) {
    contacts[contacts.length] = {
    firstName = firstName;
    lastName = lastName;
    phoneNumber = phoneNumber;
    email = email;
};

add("John", "Smith", "johnsmith@gmail.com", "123-444-333");

list("John");


#2

This one worked for me:

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() {
for (var i = 0; i < contacts.length; i++) {
printPerson(contacts[i]);
}
}

/*Create a search function
then call it passing "Jones"*/
var search = function (lastName) {
for (var i = 0 ; i < contacts.length ; i++) {
if (contacts[i].lastName === lastName) {
printPerson(contacts[i]);
}
}
}
search("Jones");

function add (firstName , lastName , email , phoneNumber) {
contacts[contacts.length] = {
firstName : firstName,
lastName : lastName,
email : email,
phoneNumber : phoneNumber
}
}
add( "Edward" ,"Jabeel" , "edward.jabeel@example.com", "1234567890" );
list();


#3

Thank you! It worked!!


#4

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