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 trialNareg Keledjian
1,674 PointsIncorrect 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?
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
231,248 PointsThe 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.
Nareg Keledjian
1,674 PointsNareg Keledjian
1,674 PointsGot 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!