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

I am completely stuck. I don't see how else I could solve this problem. Someone help?

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

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

const student = new Student(3.9);
```

You're really close! Just check your comparison symbols, in particular:

• `if (this.credits >= 90) {` this tests for greater or equal to 90
• `} else if (this.credits <= 60 && this.credits <= 31) {` only true when less than or equal to 31

The way you solve the exercise is not a bad idea, but if you want to make the code shorter. make a variable that prints the output and then prints it out at the end.

example:

```  get level () {
let output = "";
if (this.credits > 90) output += "Senior";
if (this.credits <= 90 && this.credits >= 61 ) output += "Junior";
if (this.credits <= 60 && this.credits >= 31 ) output += "Sophomore";
if (this.credits <= 30) output += "Freshman";

return output;
}
```

Runs through all ifs until it finds the right one and stores the string in output. And no more unnecessary returns and the structure is easier to read.

But the "return" statements can make the code even more compact, and no variable needed:

```  get level() {
if (this.credits > 60) return "Top";
if (this.credits > 40) return "Upper";
if (this.credits > 20) return "Middle";
return "Lower";
}
```

Note that this example has been altered so it is not valid for solving the challenge.

Hey Steven Parker,

Ooooh nice that I had not thought of always nice to see how other people solve this problem. thx Steven is there a shorter way or is 4 lines the least?

Are you familiar with the "ternary" expression? You can do it in one line that way.

Yes if I am not mistaken it is this (?) but that makes the choices between 2 variablens (true or false) how can you write it in one line then?

They can be nested:

```    get level() {
return this.credits > 33 ? "Ace"   :
this.credits > 22 ? "King"  :
this.credits > 11 ? "Queen" : "Jack";
}
```

For visual clarity I split it across 3 lines but it's just one statement.
Note that this is for example only and I'm not advocating it as a better solution.
Also note that this example has been altered so it is not valid for solving the challenge.

Wow really nice man thank you. Have learned a lot.

Conor & Stephen - thanks. Appreciate you sharing that code. That worked well. I implemented it with a different scenario. Terese

Glad to hear you didn't just copy a solution, good job!

And that made me realize that these examples don't actually need to be functional to make their point, so I altered them so they cannot be pasted in as solutions.

get level() { if (this.credits > 90) { return "Senior"; } else if (this.credits >= 61) { return "Junior"; } else if (this.credits >= 31) { return "Sophomore"; } else { return "Freshman"; } }