JavaScript Object-Oriented JavaScript Getters and Setters Creating Getter Methods

Joseph Gleiter
Joseph Gleiter
4,506 Points

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

this works in chrome but not in treehouse

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

const student = new Student(3.9, 8);


1 Answer

Steven Parker
Steven Parker
176,321 Points

There's just one value for which this method returns no value, and the challenge checker just happened to try it (but you didn't when working in Chrome)! Look over your logic and see if you can spot it.

Suggestion: one way to guarantee a value is always returned is to use a plain "else" at the end instead of another "else if". And in this case, since all the other conditions cause a return, you can even omit the "else" entirely.

Spoiler: The value which is not caught by the tests when spelled out backwards is "ytriht". :wink: