JavaScript Object-Oriented JavaScript Getters and Setters Creating Getter Methods

Mary Paul
Mary Paul
13,791 Points

"Your conditional statement is returning the wrong student level"

Any ideas why this is catching an error?

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

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

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

    if (credits>90) {
      return "Senior";
    }
    else if (credits>61 && credits<91) {
      return "Junior";
    }
    else if (credits>30 && credits<61) {
      return "Sophomore";
    }
    else {return "Freshman";}
  }
}

const student = new Student(3.9);

1 Answer

Elijah Quesada
Elijah Quesada
Front End Web Development Techdegree Graduate 31,100 Points

You were so close. It has to do with your if else statement for credits > 61. I changed it to > 60 and passed.

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

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

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

    if (credits>90) {
      return "Senior";
    }
    else if (credits>60 && credits<91){  
      return "Junior";
    }
    else if (credits>30 && credits<61) {
      return "Sophomore";
    }
    else {return "Freshman";}
  }
}

const student = new Student(3.9);