Whats wrong with my code?


#1



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 add = function(firstName,lastName,email,phoneNumber){
contacts[contacts.length] ={
    firstName=firstName;
    lastName=lastName;
    email=email;
    phoneNumber=phoneNumber;
};
};
add("jay","bah","jaiar95@gmail.com",943929394);
list();
    



Replace this line with your code.


#2

Hi this line

add("jay","bah","jaiar95@gmail.com",943929394);

you should put the " " around the number


#3

its says error still


#4

then this is an object

contacts[contacts.length] ={
    firstName=firstName;
    lastName=lastName;
    email=email;
    phoneNumber=phoneNumber;
};

so first yous should change the = with : then change the ; with ,


#5

so i got it but is contacts an array or object?


#6

contacts is an array then when you do that

contacts[contacts.length] = {
     firstName : firstName,
     ......
}

you are putting a object at the last index of the array contacts with contacts[contacts.length]


#7

thankyou got it!:slight_smile: :slight_smile: