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 trialLauren Pinckney
Courses Plus Student 7,229 PointsWhy am I getting error: "student.stringGPA is not a function"?
Inside the stringGPA() method, convert the value of the gpa property to a string and return it.
class Student {
constructor(gpa, stringGPA){
this.gpa = gpa;
this.stringGPA = stringGPA;
}
stringGPA(){
return toString('gpa');
}
}
const student = new Student(3.9);
5 Answers
Bezawit Ayfera
11,166 Pointsyou should call the toString() method on the property:-
class Student {
constructor(gpa){
this.gpa = gpa;
}
stringGPA(){
return (this.gpa).toString();
}
}
const student = new Student(3.9);
Steven Parker
231,275 PointsYou won't need to add a new property for this challenge. And adding one with the same name as the method replaces the method, then it becomes "not a function". So don't change the constructor.
And "tosString" is not a plain function, but it is a method you can attach to a numeric variable using the dot notation.
I'll bet you can get it now without an explicit spoiler.
Spencer Bigum
3,250 PointsShouldnt it be this:
class Student {
constructor(gpa, stringGPA){
this.gpa = gpa;
this.stringGPA = stringGPA;
}
stringGPA(){
return this.gpa.toString();
}
}
const student = new Student(3.9);
Steven Parker
231,275 PointsNo, that doesn't address the main issue. And explicit answers without any explanation are strongly discouraged by Treehouse and may be redacted by moderators.
Lauren Pinckney
Courses Plus Student 7,229 PointsYou guys are right, thanks!
Spencer Bigum
3,250 Pointswow first time someone has been unhappy with free help.