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 trialJulien Arseneau
Full Stack JavaScript Techdegree Student 5,200 PointsCan someone explain me how to convert a value in a string?
I can't do it inside this method inside the class
class Student {
constructor(gpa){
this.gpa = gpa;
}
stringGPA(){}
}
const student = new Student(3.9);
3 Answers
Jackson Monk
4,527 PointsThere 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
18,468 PointsFor 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.
Julien Arseneau
Full Stack JavaScript Techdegree Student 5,200 PointsThanks, I had tried the .toString method, but it wouldn't work.