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

I can't understand this challenge can someone help plz!

Inside the stringGPA() method, convert the value of the gpa property to a string and return it.

adding_methods.js
class Student {
    constructor(gpa){
        this.gpa = gpa;
    }
    stringGPA(this.gpa) {
    }
}

const student = new Student(3.9);

4 Answers

Steven Parker
Steven Parker
210,863 Points

Method parameters should be simple names (no "dot" constructs). But you don't need a parameter for this method.

You will need a "return" in the method body, to pass back the string version of the stored gpa value. And the "toString()" method could be handy here.

Steven Parker
Steven Parker
210,863 Points

Perhaps adding these hints as comments will make it more clear:

    stringGPA(this.gpa) {
//            ^^^^^^^^
//            parameter not needed (and no "dot" allowed in a parameter name)

//      <-- then add a "return" to pass back the string version of the gpa
    }

It would be great if you wrote this in code your answer isn't clear to me.

Steven Parker
Steven Parker
210,863 Points

The whole point of the challenge is to give you the experience of writing the code. Give it your best shot, and if you still have trouble passing the challenge, post the code you've added here and we can give you some more specific pointers for fixing it.

class Student { constructor(gpa, stringGPA){ this.gpa = gpa; } stringGPA(gpa){ return this.gpa = 'stringGPA' }

}

const student = new Student(3.9);

Sean Gibson
Sean Gibson
35,125 Points

class Student { constructor(gpa){ this.gpa = gpa; } stringGPA(){ return this.gpa.toString()} }

const student = new Student(3.9);