Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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
229,744 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.