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 trialHaardik Gupta
Full Stack JavaScript Techdegree Student 5,459 Pointsconvert to string classes
in this exercise im being asked to convert the value of the gpa property to a string inside of the stringGPA method
but i cant seem to understand what that means
class Student {
constructor(gpa, stringGPA){
this.gpa = gpa;
this.stringGPA = stringGPA;
}
stringGPA() {
console.log(this.gpa);
}
}
const student = new Student(3.9);
4 Answers
Steven Parker
231,248 PointsDimitar is partially correct, but when they say "convert the value" they mean just to create the return value, not to change what is being stored:
return this.gpa.toString();
You should also not modify the provided constructor code. Just add the new method.
Dimitar Dimitrov
11,800 PointsIn the stringGPA method you just need to use the JavaScript method toString()
on this.gpa
and assign its new value like this:
return this.gpa = this.gpa.toString();
toString() method converts your data to a string that is all you need to do
Haardik Gupta
Full Stack JavaScript Techdegree Student 5,459 Pointsim getting an error saying
Bummer: student.stringGPA is not a function
with 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,248 PointsFor this challenge, you are asked only to add a new method. The instructions don't say anything about modifying the constructor code that was provided.
Haardik Gupta
Full Stack JavaScript Techdegree Student 5,459 Pointsthank you for the help