6 we made a friend. please help


#1

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


#2

Hi after that you should use the function add like that

add("franck", "Kolla", "exemple@hotmail.com", "0762028");

#3

function add(firstName, lastName, email, phoneNumber) {
var contacts[contacts.length] = {
firstName: firstName,
lastName: lastName,
email: email,
phoneNumber: phoneNumber
}
};
list()
add("franck", "Kolla", "exemple@hotmail.com", "0762028");

it doesn't work to,


#4

Just remove the var before contacts[contacts.length]

It shoud look like this:

var add = function(firstName, lastName, email, phoneNumber){
        contacts[contacts.length] = {
        firstName: firstName,
        lastName: lastName,
        phoneNumber: phoneNumber,
        email: email
        }
    };
    add("franck", "Kolla", "exemple@hotmail.com", "0762028");

list();

#5

thx a lot now it works


#6

I did a little bit different. Worked like a charm. Function add is extremally simple and straightforward.

The Purpose is to add a new objet into the array of objects.
This is the key line:
contacts[contacts.length] = new add("Paul", "love", "Paul@test.com", "333-3333");

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]);
}
}

function add(firstName, lastName, email, phoneNumber) {
this.firstName = firstName;
this.lastName = lastName;
this.email = email;
this.phoneNumber = phoneNumber;

}

contacts[contacts.length] = new add("Paul", "love", "Paul@test.com", "333-3333");