6/6 what is wrong


#1

what have I done wrong??

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, contact];

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, email, phoneNumber) {
contacts [contacts.length] = {
firstName: firstName,
lastName: lastName,
email: email,
phoneNumber: phoneNumber
}
};

add("Marnie","MacIver","07590465121","marnie.maciver@gmail.com")

list();


#2

Try this for the add funtion

function add(firstName,lastName,email,telephone){
    var  personObject = {
        firstName:firstName,
        lastName:lastName,
        phoneNumber:telephone,
        email:email
        
    };
    contacts[contacts.length] = personObject;// or contacts.push(personObject)

then finally you do

add("Marnie","MacIver","07590465121","marnie.maciver@gmail.com")

#3

What exactly is the problem, what error shows up?


#4

dont worry i worked it out thanks