JavaScript Object-Oriented JavaScript Getters and Setters Creating Getter Methods

Susan Stufflebean
Susan Stufflebean
7,466 Points

Error stating credits are not defined?

Why am I getting credits not defined error? Is there an issue with this task?

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

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

  }

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

const student = new Student(3.9);

1 Answer

Antti Lylander
Antti Lylander
9,659 Points

use this.credits as credits refers to a global variable credits which does not exist.