We made a Friend!


What do you people think about this approach?

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

It seems to be working, but I've seen other ways to complete this, using the parameter: value option. Is there a reason to prefer one to the other or... whatever works? :wink:


It would be interresting to see what you get with a

console.log( contacts );

+++ this explained


google search
== the Book ==
javascript this site:developer.mozilla.org
Have a read through


I tried something like
function add (firstName, lastName, email, phoneNumber) {
var contact = {
firstName: firstName,
lastName: lastName,
phoneNumber: phoneNumber,
email: email
contacts[contacts.length] = contact;
But the CodeAcademy says that: "doesn't have a phoneNumber property." How not?


I solved the trouble. It was created a objecjt previously in another line without the 'phoneNumber' property and I put this object on the array. So, The CodeAcademy engine found it and showed like a problem. So, when I've put the 'phoneNumber' property in the object, the code has been accepted. SUCCESS!!!