Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript Object-Oriented JavaScript Getters and Setters Creating Getter Methods

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
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

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:

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