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

where am i doing this wrong?.

Challenge Task 1 of 2 Inside the Student class, create an empty getter method called level().

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

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

  get level() {
      const student = new Student(3.9)
      const credits = student;
      if (credits > 90) {
        return 'Senior';
      } else if (credits > 61 && credits <= 90) {
        return 'Junior';    
      } else if (credits > 31 && credits <= 60) {
        return 'Sophomore';
      } else {
        return 'Freshman';
      }
}

}

var student = new Student(3.9, 60);

2 Answers

Steven Parker
Steven Parker
231,269 Points

Are you sure you're just on task 1? That's quite a bit more than an "empty" method! But it should pass — try restarting your browser and do it again.

And this looks like the code for task 2, but I see two issues:

  • it should work with the "credits" of the current object (this), don't create a new one
  • make sure your range values match the requirements in the instructions
Habiballah Hezarehee
Habiballah Hezarehee
7,193 Points

In the second task which you have already implemented, you need to refer the credits variable to current object which is being created. To do that you just need to add this. before credits anywhere you have used it. Good luck