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 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
216,033 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