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 trialGregory Ford
7,109 PointsNot quite sure how to do this...
I'm lost as to what I am supposed to do here. I know the backing property needs an underscore _ but the rest of the assignment has me lost. Can anyone help? Thanks in advance,
class Student {
constructor(gpa, credits){
this.gpa = gpa;
this.credits = credits;
}
stringGPA() {
return this.gpa.toString();
}
get level() {
if (this.credits > 90 ) {
return 'Senior';
} else if (this.credits > 60) {
return 'Junior';
} else if (this.credits > 30) {
return 'Sophomore';
} else {
return 'Freshman';
}
}
set major(major) {
this._major
}
}
var student = new Student(3.9, 60);
1 Answer
Jason Larson
8,361 PointsIf you're on the second task, the set major(major) method should be empty, so:
set major(major){}
if you're on the last task, you'll need to return the value based on the level (or on credits).
You might try something like return this._major = <value>
. Obviously, replace <value> with the correct value, and you'll need to wrap it in a conditional.
Gregory Ford
7,109 PointsThanks!
Jason Larson
8,361 PointsJason Larson
8,361 PointsThis was not part of the challenge, nor part of your question, but I just thought I'd throw this out there... In your get level() method, you don't need to do all the else if's (or even the else). If your condition is true, it's going to return a value, so it won't ever check the rest of the conditions, so you can just do: