Question About Object Names "We Made a Friend"


#1

I had a bit of trouble with the last exercise (“We Made a Friend”). I tried to create a new object within the function but had trouble when trying to name the object.
Looked something like this:
function add(firstName, lastName, phoneNumber, email){
var firstName = function Contact(firstName, lastName, phoneNumber, email) {
this.firstName = firstName;
this.lastName = lastName;
this.phoneNumber = phoneNumber;
this.email = email;
}
contacts.push(firstName)
}

Does the name of the object not matter? What is the object’s name with the following code (which did work):



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

add('Jo', 'Smith', '(675) 564 - 3456', 'asljhf@example.com');
list();
console.log(contacts);


#2

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.