JavaScript Object-Oriented JavaScript Getters and Setters Creating Getter Methods

What am I doing wrong? 'Bummer: Your conditional statement is returning the wrong student level.'

Not sure what is wrong with the code. I've checked the other questions and it seems like the code is in line with what people have said to fix.

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 <= 90 && this.credits >= 61) {
        return 'Junior';
      } else if (this.credits <= 60 && this.credits >= 31) {
        return 'Sophmore';
      } else if (this.credits <= 30) {
        return 'Freshman';

const student = new Student(3.9);

3 Answers

Andrew Hinkson
Andrew Hinkson
14,056 Points

Everything looks good except you may check your spelling on your student levels.

Lee Nolan
Lee Nolan
21,690 Points

Also, whilst not technically incorrect, you do not need the final 'else if' can just do;

else { return 'Freshman'; }

This is because junior/senior/sophomore have already evaluated as false, so freshman is the only possible outcome by now.

Michael Kroon
Michael Kroon
16,253 Points

Lee is correct in that you technically don't need that last 'else if'. You can use a simple 'else' since it's the final condition. It'll still run...

I also checked Andrew's suggestion but the name of the getter is correct...

The problem was in your spelling of 'Sophomore'. Your code has 'Sophmore', so it wasn't returning the correct string if the credits variable was sit to between 31 and 60...

So after I corrected the spelling, it worked. :)