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 Getter Methods

Jesus Mendoza
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Jesus Mendoza
Full Stack JavaScript Techdegree Graduate 20,337 Points

Unexpected token >=

I can't figure out what I'm doing wrong here. "Unexpected token >=" keeps popping up.

creating_getters.js
class Student {
    constructor(gpa, credits){
        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 && >= 61) {
                return 'Junior';
        } else if ( studentCredits <= 60 && >= 31) {
                return 'Sophomore';
        } else if ( studentCredits <= 30) {
                return 'Freshman';
        }

    }
}

const student = new Student(3.9);

1 Answer

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hi Jesus,

The error is not very detailed, but it is telling you that something right before the symbols >= in the code is wrong. There are 3 instances of this symbol. The first one is the if conditional to compare studentCredits to 90. This one is fine.

The error is occurring in the first else if conditional (and will also occur in the third). When using boolean operators (her the &&), you have to tell the compiler what you are comparing one to the other on both sides of the operator.

So

variableToCompare >= value1 && <= value2

Will return an error. The compiler has no idea what to compare value2 to. So, it you need to repeat the variable that is comparing to. Like

variableToCompare >= value1 && variableToCompare <= value2

Once you fix up those two instances, the rest looks good.

Nice work! :) :dizzy: