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 trialSamira Tavakolli
6,715 PointsConvert 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 {
constructor(gpa){
this.gpa = gpa;
}
stringGPA (){
string(this.gpa);
}
}
const student = new Student(3.9);
2 Answers
Steven Parker
231,271 PointsThere'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.
Samira Tavakolli
6,715 PointsThanks for the answer. I found that method on the link below !!! But later I found the toString().
https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_string