JavaScript Object-Oriented JavaScript Getters and Setters Creating Getter Methods

Julianna Kahn
Julianna Kahn
20,699 Points

How is it that my conditional statement is returning the wrong student level?

Is there an error in my if statement logic?

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

  get level() {
    if (this.credits > 90)  {
      return 'Senior';
      } else if (this.credits > 60) {
      return 'Junior';
      } else if (this.credits > 30) {
      return 'Sophmore';
      } else {
      return 'Freshman';
      }
  }

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

const student = new Student(3.9);

2 Answers

Steven Parker
Steven Parker
176,599 Points

Your logic is fine, you just have a spelling error. The function returns "Sophmore" instead of "Sophomore".

Otherwise, good job with the code! :+1:

Julianna Kahn
Julianna Kahn
20,699 Points

The code checking on this was certainly unforgiving. Thank you.

Steven Parker
Steven Parker
176,599 Points

Julianna Kahn — the challenges can be very picky, and about specified outputs in particular. But then computers are like that in general!

Anyway, glad to help. You can mark a question solved by choosing a "best answer".
And happy coding!