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!

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

Converting property value to string within class method is throwing an error.

I'm not sure what I'm doing wrong here. In order to convert the gpa to a string and then return it, is there a different way? I keep getting an error, saying that gpa isn't defined.

class Student {
        this.gpa = gpa;
  stringGPA() {
    return toString(this.gpa);  

const student = new Student(3.9);

1 Answer


Your JS syntax is a bit off.

You should rework your return statement.

toString is a method for a number variable object (as well as several other types of objects).

So the proper syntax would be:

return this.gpa.toString();  // Since toString is a method, you need to call it with ().
// (This will return the number as a string)

(It passes with that line of code, by the way...)

More info:



I hope that helps.

Stay safe and happy coding!