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

Julien Arseneau
seal-mask
.a{fill-rule:evenodd;}techdegree
Julien Arseneau
Full Stack JavaScript Techdegree Student 5,200 Points

Can someone explain me how to convert a value in a string?

I can't do it inside this method inside the class

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

}

const student = new Student(3.9);

3 Answers

There is special syntax you can use for this. Don't know if you've seen it before, but you can make a string with backticks, then using `${// Write code here}` inside the backtick string, you can input regular JS values in the curly braces and it will convert that value to a string. For you, it would look like this:

stringGPA() {
  return `${this.gpa}`;
}
Corey Montgomery
Corey Montgomery
18,468 Points

For this you need to apply the .toString() method to the gpa variable and return it through the stringGPA method. Hope that gives you enough of a hint to complete the challenge. If not, let me know.