We made a Friend!


#1

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:


#2

@teraslayer76979,
It would be interresting to see what you get with a

console.log( contacts );

+++ this explained

Reference::

google search
== the Book ==
javascript this site:developer.mozilla.org
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this
Have a read through
http://stackoverflow.com/questions/4354418/var-vs-this-vs-constructor-parameter-variables
and


#3

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?


#4

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!!!