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

James Fleming
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
James Fleming
Full Stack JavaScript Techdegree Graduate 15,848 Points

Getting an error message from treehouse "your conditional statement is returning the wrong student level"

I've looked over other students questions and can't seem to find out why my code won't work. Any help here is very much appreciated. I've seen other ways of coding this but I'd like to find out why mine isn't working the way I've attempted it. Thanks for any help!!

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


}

const student = new Student(3.9);
James Fleming
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
James Fleming
Full Stack JavaScript Techdegree Graduate 15,848 Points

Update: I caught the misspelling of "Sophomore" and fixed it. It still doesn't work and now says "Bummer: It looks like your getter method is not returning a value." I'm sure I'm missing something small but just can't catch it.

1 Answer

James Fleming
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
James Fleming
Full Stack JavaScript Techdegree Graduate 15,848 Points

I was able to fix it. The two problems were:

  1. Misspelled "Sophomore"
  2. I needed to = sign in the last else if so it should be else if (this.credits <= 30)