JavaScript Object-Oriented JavaScript Getters and Setters Creating Getter Methods

Susan Stufflebean
Susan Stufflebean
7,466 Points

Why is my conditional statement incorrect now that I have corrected my credits undefined error?

??????

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

  get level() {
  if (this.credits > 90) {
        return 'Senior';
      } else if (this.credits > 61 && this.credits <= 90) {
        return 'Junior';    
      } else if (this.credits > 31 && this.credits <= 60) {
        return 'Sophomore';
      } else 
        return 'Freshman';{
        }

  }


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

const student = new Student(3.9);

2 Answers

Jennifer Nordell
STAFF
Jennifer Nordell
Treehouse Staff

Hi there! You're doing great! The code that you're writing was meant to include 61 points in the "Junior" level and 31 points in the "Sophomore" level. Imagine for a moment the student has exactly 61 points, You are saying "If a student has greater than 61 points and less than 90, mark them as a Junior". That will evaluate to false because 61 is not greater than 61. Otherwise, if the student has greater than 31 points and less than 60 points, mark them as a "Sophomore". This will also be false. Sixty-one is not less than 60. If none of those work, mark them as a "Freshman". So, in this case, a student with 61 points will be marked "Freshman".

This same logic is happening for students with exactly 31 points. They will also be marked as "Freshman". In these two conditions, you need the >= instead of just the >.

Hope this helps! :sparkles:

Susan Stufflebean
Susan Stufflebean
7,466 Points

Thank you!!!!! I have been messing with this challenge for aver 2 hours geez!!!!!!!!