JavaScript Object-Oriented JavaScript Getters and Setters Creating Setter Methods

Isolde Falke
Isolde Falke
56 Points

Invalid left-hand side. I really don't have a clue what I need to do with this task. Help would be appreciated :))

I really don't get what I need to do in this task. Please help me.

I don't know how I can add a value to the 'major' variable.

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

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


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

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

      set major(major) {
        this._major = major;
        if (student.level = 'Senior' || student.level = 'Junior') {
        major = student.major;
        } else {
        major = 'None';
        }
    }

}

var student = new Student(3.9, 60);

3 Answers

The error Bummer: Invalid left-hand side in assignment refers to this line

if (student.level = 'Senior' || student.level = 'Junior') {

You are using assignment operators instead of comparison operators

Darryl Mah
Darryl Mah
5,486 Points

What Kris said. Change the “=“ to “==“ or “===“ and you should be good.

Isolde Falke
Isolde Falke
56 Points

OHH you're so right. Thanks so much ! Now I have another problem: Your setter method is returning the wrong value for the major property. :(

Darryl Mah
Darryl Mah
5,486 Points

Use the "this" keyword instead of student ;)