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,354 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