JavaScript Practice Classes in JavaScript Practicing Classes Practice Adding Methods

Caroline Louw
Caroline Louw
7,917 Points

How do i add the method changeUsername() to the class User?

I tried creating the method but it says there is a unexpected token }

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

        changeUsername(username) {
        this.username = username;
      }

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

1 Answer

Clayton Perszyk
MOD
Clayton Perszyk
Treehouse Moderator 46,556 Points
class User {
    constructor(email, username, birthday, changeUsername) { // remove changeUsername from here
        this.email = email;
        this.username = username;
        this.birthday = birthday;
        this.changeUsername = changeUsername; // remove this line
    }

        changeUsername(username) {
        this.username = username;
      }

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