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 trialJason Berry
5,180 PointsI don't understand why me else and if will not back the setter.
Im not quite sure whats going wrong with my code. I have the understanding that I'm supposed to write an else and if code.
class Student {
constructor(gpa, credits,level){
this.gpa = gpa;
this.credits = credits;
this.level = level;
}
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) {
if (this.level > 'Senior' ) {
return 'Senior';
} else if (this.level > 'Junior') {
return 'Junior';
} else if (this.level > 'Sophmore') {
return 'none';
} else if (this.level > 'Freshman'){
return 'none';
}
}
}
var student = new Student(3.9, 60);
1 Answer
Steven Parker
231,236 PointsThe instructions say the setter should update a backing property using either the argument or 'None', but this code doesn't do that. There's an example of how to make a backing property in the previous video if you need a refresher.
And it's not necessary for a setter to return anything.
Also, be careful of spelling. You have "Sophmore" (missing an "o") instead of "Sophomore".