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 trial

JavaScript Object-Oriented JavaScript Working with Classes in JavaScript Adding methods to classes

Convert a value to string!

I try to compleat the method inside this class but I get an error as the string() is not defined. I am using this method to convert the value of gpa ( which is a number) to a string but I get that error. Would you please help me :)

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

const student = new Student(3.9);

2 Answers

Steven Parker
Steven Parker
230,274 Points

There's no common function named "string", but numbers have a method called .toString() that could be handy.

Also, this method needs to return the converted value.

Thanks for the answer. I found that method on the link below !!! But later I found the toString().