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

Bummer: It looks like your code is not returning a value...

I ran this in VSCode and in the console and it returned the correct value when passing in a credits parameter on 'student' and then running console.log(student.level); I'm not sure why it's not being accepted

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

      switch (true) {
        case (this.credits > 90):
          return "Senior";
          break;
        case (this.credits > 60):
          return "Junior";
          break;
        case (this.credits > 30):
          return 'Sophomore';
          break;
        case (this.credits < 30):
          return "Freshman";
          break;
      }

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

const student = new Student(3.9);

1 Answer

Cameron Childres
Cameron Childres
11,820 Points

Hi Jake,

Your code doesn't account for a situation where the credits are exactly 30. If you alter your last conditional to be "less than or equal to" you should be able to pass:

case (this.credits <= 30):
          return "Freshman";
          break;

You're right! Thanks so much, not sure how I missed that...