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 Getters and Setters Creating Getter Methods

i don't know

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

stringGPA() { return this.gpa.toString(); }

const student = new Student(3.9, stringGPA);

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

   stringGPA() {
    return this.gpa.toString();
}



const student = new Student(3.9, stringGPA);

2 Answers

Steven Parker
Steven Parker
231,269 Points

I see two issues:

  • unless the instructions ask you specifically (these don't), never modify the provided code (just add to it)
  • you still need to create the getter method named "level"

If you're unclear on the syntax for a getter method, you might want to review the Getters video.

thanks

Mike Siwik
seal-mask
.a{fill-rule:evenodd;}techdegree
Mike Siwik
Full Stack JavaScript Techdegree Student 8,483 Points

I passed with flying colors. in quotes you put the variable/this.credits a greater than or less than symbol followed by an equal sign. ampersand, then the other credit number.

I changed this.credits to something smaller in the getlevel() function with const. And it worked. I hope I'm not giving away too much, I'm just trying to point future coders in the right direction. Watching Getters video prior to this challenge helped out a lot.