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

Thomas Tilton-Heylin
Thomas Tilton-Heylin
12,098 Points

create an empty setter method called "major()"

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) {
    this._major = major;
    if (level() = 'Senior' || 'Junior') {
        this._major = major;
        } else {
        this._major = 'none';
        }
  }
}

var student = new Student(3.9, 60);
Steven Parker
Steven Parker
231,269 Points

I know "jk" is commonly used as a abbreviation for "just kidding". But I don't get the joke?

Hi Thomas

I have changed your title from "k" to the name of the challenge your referring to

Giving a descriptive title will give you more chance of finding a solution.

code of conduct

2 Answers

Steven Parker
Steven Parker
231,269 Points

I did spot some issues:

    if (level() = 'Senior' || 'Junior') {
  • reference to a "getter" property should be done like a normal one, use "this.level" instead of "level()"
  • only complete conditional tests can be combined with logic operators
  • one "=" is an assignment operator, use two ("==") for comparisons

For any future questions, please be sure to describe your issue in complete sentences, and give your question a descriptive title.

steven parker just give the answer the two tasks are complicated

Steven Parker
Steven Parker
231,269 Points

This is a rather old question. If you have an issue not addressed by this one, you might consider posting a new questions of your own.