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

Jeffrey Sevinga
Jeffrey Sevinga
8,497 Points

The getter method should return the level of a student, based on how many credits (this.credits) they have. Broken?

My code works in Workspaces but the challenge keeps giving me Bummer: It looks like your getter method is not returning, Challenge broken? I don't get it, if it works in Workspaces it should be fine.

class Student {
    constructor(gpa, credits){
        this.gpa = gpa;
        this.credits = credits;
    }

    stringGPA() {
        return this.gpa.toString();
    }

    get level(){
            let currentCredits = this.credits;        
            if (currentCredits > 90) {
            return 'Senior';
        } else if (currentCredits <= 90 && currentCredits > 60) {
              return 'Junior';        
        } else if (currentCredits <= 60 && currentCredits > 30) {
              return 'Sophomore';      
        } else if (currentCredits < 30) {
              return 'Freshman';     
        }
    }
}

const student = new Student(3.9, 65);
console.log(student.level);

4 Answers

What if the value is exactly 30. Freshman needs to be <= 30.

Jeffrey Sevinga
Jeffrey Sevinga
8,497 Points

Damn :P thank you! Definitely need to read beter what i write

Your condition for Sophomore and Freshman both have condition:

currentCredits > 30

You need to modify the Freshman condition.

Jeffrey Sevinga
Jeffrey Sevinga
8,497 Points

Yes i see that's not good :O

But i changed it to < less then 30 and i still get the same error

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

Ali .
Ali .
15,521 Points
class Student {
    constructor(gpa, credits){
        this.gpa = gpa;
        this.credits = credits;
    }
     get level(){
        let credits = this.credits;

        if (credits > 90) {return 'Senior';}

        else if (credits <= 90 && credits >= 61 ) {return 'Junior';}

        else if (credits <= 60 && credits >= 31) {return 'Sophomore';}

        else if (credits <= 30 ) {return 'Freshman';}
}
    stringGPA() {
        return this.gpa.toString();
    }
}

const student = new Student(3.9);
console.log(Student.level);
Henry Hayden
Henry Hayden
7,572 Points

You can also leave off the last if statement, since the rest of the values will result in returning Freshman.

else { return 'Freshman' ;}