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 trialBashir Orfani
13,170 PointsAdd a method to the User class called changeUsername()
Add a method to the User class called changeUsername() This method should receive one parameter username, a string representing a new username for the user1 object. This method should not return anything Inside the method, update the value of the username property to the value of the username parameter
class User {
constructor(email, username, birthday) {
this.email = email;
this.username = username;
this.birthday = birthday;
}
changeUsername(username) {
this.username = username;
user1.changeUsername("TreehouseStudent2");
}
}
3 Answers
immad Ud din
Front End Web Development Techdegree Student 14,756 Pointsclass User {
constructor(email, username, birthday) {
this.email = email;
this.username = username;
this.birthday = birthday;
}
changeUsername(username) {
this.username = username;
}
}
let user1 = new User('abc@hotmail.com', 'xyz' , '0000/00/00');
console.log(user1.username);
user1.changeUsername("TreehouseStudent2");
console.log(user1.username);
Bashir Orfani
13,170 PointsThank you so much immad Ud din .
Diane Bond
8,011 PointsFYI you do not need to change all the parameters; the only one that is required is username; therefore only the second to last line of code is required.
Peter Hiks
642 Pointshere is the answer
class User {
constructor(email, username, birthday) {
this.email = email;
this.username = username;
this.birthday = birthday;
}
changeUsername(username) {
this.username = username;
}
}
var user1 = new User('JavaScriptStudent@teamtreehouse.com', 'JSUser1', '1/08/1991');
user1.changeUsername("username");
immad Ud din
Front End Web Development Techdegree Student 14,756 Pointsimmad Ud din
Front End Web Development Techdegree Student 14,756 Pointsyour code is giving a RangeError: RangeError: Maximum call stack size exceeded. The right way is to create an object outside the class scope and then call its changeUserName method to update the name.