JavaScript Object-Oriented JavaScript Getters and Setters Creating Getter Methods

Chris Walker
Chris Walker
4,862 Points

I think your editor is looking for specific syntax despite what I have returning a valid response.

Why's my syntax considered incorrect?

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

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

    get level() {
      const credits = this.credits;

      if (credits > 90){
        return 'Senior';
      } else if (credits > 60){
        return 'Junior';
      } else if (credits > 30){
        return 'Sophmore';
      } else {
        return 'Freshman';
      }
    }
}

const student = new Student(3.9,60);

1 Answer

Dave StSomeWhere
Dave StSomeWhere
19,779 Points

You are not returning a valid response since you have a spelling error on one of your return values. Your logic is correct (not sure why you defined a variable for credit as opposed to just using this.credits). :tropical_drink: :palm_tree:

Chris Walker
Chris Walker
4,862 Points

Ha. Thanks. It was just that spelling error. As for the 'this.credits', I didn't care for the repeated this. over and over. Wanted to clean up the syntax.