Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.


Code review: JavaScript constructors and prototpyes

// here i'm creating a new constructor for a user object
function User(first_name, last_name, email, password, friends, favorites) {
    this.first_name = first_name;
    this.last_name = last_name;
    this.email = email;
    this.password = password;
    this.friends = [];
    this.favorites = [];

// this function adds a new friend to the friends array
User.prototype.add_friend = function(friend) {

// this function deletes a friend from the friends array 
User.prototype.delete_friend = function(friend) {
    this.friends.splice(this.friends.indexOf(friend), 1);

// this function adds a favorite to the favorites array
User.prototype.add_favorite = function(favorite) {

// this function deletes a favorite from the favorites array
User.prototype.delete_favorite = function(favorite) {
    this.favorites.splice(this.favorites.indexOf(favorite), 1);

var user = new User("Andrew", "Chalkley", "andrew@teamtreehouse.com", "secretpassword");

I'm mainly concerned about the 'delete' functions that are supposed to splice a friend or favorite from it's array.