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

Inside the getter method use the conditional statement of your choice to determine the level of the student. If the valu

Inside the getter method use the conditional statement of your choice to determine the level of the student. If the value of the "credits" property is over 90, return 'Senior'. If it's between 61 and 90, return 'Junior'. If it's between 31 and 60, return 'Sophomore'. If it's 30 or less, return 'Freshman'.

creating_getters.js
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 (credits >= 61 && credits <= 90 )
        return Junior
      else if (credits >= 31 && credits <= 60)
        return Sophomore
      else (credits <= 30 )  
        return Freshman
   }
}

const student = new Student(3.9);

It's best to ask specific questions, in addition to pasting the code and problem you are working on. How far have you gotten? what do you understand? what doesn't make sense?

Answering these questions can help you begin to get better responses.

1 Answer

BERYL YOUNG
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
BERYL YOUNG
UX Design Techdegree Graduate 39,697 Points

Take a look at your first two conditional statements you have the same upper and lower limits. What happens at 90? Does senior lower limit need 90 or 91 and more? What is Junior upper limit is it 89 or 90? figure out what these limits should be. Also pay attention to the conditionals used. You have >= and <= . The equal sign will pick up on both of these conditionals resulting in the first conditional capturing for 90.

I hope that this helps you figure it out.