Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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
210,066 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,799 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
210,066 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