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.

JavaScript Practice Classes in JavaScript Practicing Classes Practice Instantiating an Object

Incorrect value for object property while instantiating an object - working with javascript classes

Hey everyone,

I am getting an error while working with the "Practice Classes in JavaScript". The exercise asks to provide an email, username and birthday attribute to a new instance of the User class.

The error claims that I have an incorrect value for the object 'birthday'; am I formatting this incorrectly? Or is this a different issue altogether?

User.js
class User {
    constructor(email, username, birthday) {
        this.email = email;
        this.username = username;
        this.birthday = birthday;
    }
}

let user1 = new User (
  {
   email: 'JavaScriptStudent@teamtreehouse.com', 
   username: 'JSUser1', 
   birthday: '1/08/1991'
  }
)

1 Answer

Steven Parker
Steven Parker
220,415 Points

The constructor builds the object for you, so instead of passing an object in as the argument, just pass the individual values you want the constructor to use when making the object.

Got it; I suspected something was up with my formatting. Using this MDN page as a guide (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Working_with_Objects) I adjusted the formatting like so and it worked:

let user1 = new User ('JavaScriptStudent@teamtreehouse.com', 'JSUser1', '1/08/1991').

Thank you for clarifying, Steven Parker!