Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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
231,269 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!