JavaScript

Diogo Pinto
Diogo Pinto
3,526 Points

My Solution - simpler code using a multiple statement ternary operator (equivalent to chained if/else clauses).

I feel that the ternary syntax might seem daunting at first, but the more you use it and come across it, the more you appreciate the fact that it is much less verbose and way cleaner in my opinion. Here's my solution to this Code Challenge (19612).

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

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

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

Diogo Pinto
Diogo Pinto
3,526 Points

Sorry guys, I intended this to show up as part of the discussion for one of the OOP code challenges. More specifically, this one: https://teamtreehouse.com/library/objectoriented-javascript-2/getters-and-setters/creating-getter-methods

If anyone can shine a light on how I can transfer my post (or redo it) in the right place, I'd appreciate.

Thanks for reading!

Steven Parker
Steven Parker
171,343 Points

If you start the question using the "get help" button on the video page, it should get a link button and show up on that page's "questions" tab.