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

Ha Yeong Jeong
Ha Yeong Jeong
4,940 Points

Why does my code work well in the web browser console but not on the challenge page?

It keeps giving an error saying the wrong level is given, but the code looks fine on the web console giving the correct outputs. Can you help and figure out what the issue is with my getter method?

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

    }
}

const student = new Student(3.9);

2 Answers

Steven Parker
Steven Parker
229,920 Points

The browser can't tell if your code meets the requirements, but the challenge will. For example, the instructions say "If the student has 90 or fewer credits, but more than 60 (>= 61), they are a 'Junior'." So this means a student with 60 credits is not a Junior. But the code shown above will say "Junior" for anyone with 60 credits.

There is a similar issue with the limit for Sophomore.

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,858 Points

Hi Ha Yeong Jeong

Your conditionals for the second task are not quite right. For example, the second one states that they must have more than 60 credits, but your conditional will pass if they have only 60 credits and that is incorrect. If you have a look at the question again, the correct conditional is actually written right into the question itself. If you just change yours to match what the question states, the code will pass.

Nice work! :) :dizzy:

Jason Anders
Jason Anders
Treehouse Moderator 145,858 Points

Steven types a bit faster than I it seems. Lol. :)

Steven Parker
Steven Parker
229,920 Points

Not necessarily, I probably just logged in earlier.

Ha Yeong Jeong
Ha Yeong Jeong
4,940 Points

Thank you. I appreciate your help.