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

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
231,184 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
231,184 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
231,184 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
38,363 Points

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

const student = new Student(3.9);