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);
Joseph Wasden
Joseph Wasden
20,371 Points

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
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.