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
172,335 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