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

convert 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

adding_methods.js
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
Steven Parker
231,268 Points

Dimitar 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
Dimitar Dimitrov
11,800 Points

In 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

im 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
Steven Parker
231,268 Points

For 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.

thank you for the help