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 Object-Oriented JavaScript Working with Classes in JavaScript Adding methods to classes

Prakash Shrestha
PLUS
Prakash Shrestha
Courses Plus Student 2,134 Points

I am having difficulty on adding method in classs

I dont know what is wrong on code

adding_methods.js
class Student {
    constructor(gpa){
        this.gpa = gpa;
       this.stringGPA = stringGPA;
    }
}
stringGPA()
{
  console.log(this.stringGPA);
}

const student = new Student(3.9);

1 Answer

Steven Parker
Steven Parker
210,147 Points

There seems to be three issues:

  • the method needs to be placed inside the class definition (before the final brace)
  • the method should "convert the value of the gpa property to a string ,,,"
  • the method should return the converted value (not log it)