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

stringGPA

I Need a little Assistance with this one.

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

  }
}

const student = new Student(3.9);

2 Answers

Steven Parker
Steven Parker
231,184 Points

You're close, but "toString" is not a function. It's a method you would call using dot notation:

    return this.gpa.toString();
Jamie Carter
seal-mask
.a{fill-rule:evenodd;}techdegree
Jamie Carter
Front End Web Development Techdegree Student 12,096 Points

And following on from Steven, that expression is Object Oriented Javascript.

Object.toString() is just what you are building for Student.stringGPA()

Lots of base things like arrays and objects have these kinds of properties. It blew my mind when I realised this.

another example is Array.length

Thank you very much, got it! Was a little bit off but its sorted now thank you.