JavaScript Object-Oriented JavaScript Getters and Setters Creating Setter Methods

Adi Chayot
Adi Chayot
3,618 Points

Can anybody help?

I cant see what am i missing

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

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

    get level() {
        if (this.credits > 90 ) {
            return 'Senior';
        } else if (this.credits > 60) {
            return 'Junior';
        } else if (this.credits > 30) {
            return 'Sophomore';
        } else {
            return 'Freshman';
        }
    }

  set major(major){
    if(this.getlevel === 'Junior' || this.getlevel === 'Senior' ){
      this._major = 'major';
    } else if(this.getlevel === 'Freshman' || this.getlevel === 'Sophomore'){
      this._major = 'None';
    }
  }
}

var student = new Student(3.9, 60);

1 Answer

Armin Kadic
Armin Kadic
14,150 Points

Remove the "get" from "getlevel" in your loop, because "level" is the name of the getter. Also remove the quotes from "major" because it makes it into a string.

I hope this helps.