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 trialFrank Grillo
Front End Web Development Techdegree Graduate 16,715 PointsCreating Setters
I am still having trouble creating a setter properly in this exercise. Can someone explain this a little more clearly?
class Student {
constructor(gpa, credits){
this.gpa = gpa;
this.credits = credits;
}
stringGPA() {
return this.gpa.toString();
}
set major(student) {
if(this.level === 'Senior' || this.level === 'Junior') {
this._major = major;
return this._major;
} else {
this._major = 'None'
return this._major;
}
}
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';
}
}
}
var student = new Student(3.9, 60);
1 Answer
Bella Bradbury
Front End Web Development Techdegree Graduate 32,790 PointsYou're really, really close Frank! The point of this setter is to check and display a student's major. If we look at the code you've written we can see that there's a specific parameter that's being used here, major. You're going to want to pass that parameter into this setter when you're setting it up. Which means adjusting your beginning line of code to:
set major(major) {
...
}
After that, remember to add the semicolon after 'none' and you're good to go!
Steven Parker
231,268 PointsSteven Parker
231,268 PointsI would add that setters don't need to return anything.