Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript Object-Oriented JavaScript Getters and Setters Creating Getter Methods

i can't get it

inside the getter method add a conditional statement

creating_getters.js
class Student {
    constructor(gpa, credits){
        this.gpa = gpa;
        this.credits = credits;
    }
    get level() {}
    const level = new Data();
    const marks = level.getMarks();
  if(student> 90 && student <= 90) {
        return 'Senior';
  } else {      
    return 'Junior';
     return  'Freshman';
  }
    stringGPA() {
        return this.gpa.toString();
    }
}

const student = new Student(3.9);

2 Answers

Martin Lecke
Martin Lecke
14,370 Points

Hi Im not sure what you are doing with new Data() and level.getMarks(). You might think of the Date() object. But its not needed for this exercise.

We want to return a String senior, junior etc. Depending how much credits they have. When we write this.credits we get a number back saying how much credit they have. eg. 30

    get level() {
        if (this.credits > 90 ) { // if our credit is above 90 we want to do this
            return 'Senior';
        } else if (this.credits > 60) { // if our credit is above 60 we want to do this (if its above 90 the above will kick in first)
            return 'Junior';
        } else if (this.credits > 30) { // if our credit is above 30 we want to do this (if its above 60 the above will kick in first)
            return 'Sophomore';
        } else { // for the rest less than we want to return the string Freshman (this will be 30 and below)
            return 'Freshman';
        }
    }

thank you