Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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,492 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,492 Points

Use the "this" keyword instead of student ;)