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 trialLucciano Molina
7,332 PointsInside the major() setter method, set the student's major to a backing property "_major".
It's saying "unexpected { " in the code I can't seem to find it. Can someone review my code and give me some feedback, please. I am not completely sure that my code is even correct. Thank you.
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';
}
}
get major {
return this._major;
}
set major (major){
if(this.level === "Senior" || this.level === "Junior"){
return this._major = major
}else (this.level === "Sophmore" || this.level === "Freshman"){
return this._major = "None"
}
}
}
var student = new Student(3.9, 60);
1 Answer
Ella Ruokokoski
20,881 PointsYou The error message is a bit off, you should have else if instead of else inside your setter method. Also, setter does not return a value so you should remove the returns. The get major is not a method without the brackets. But that method is redundant anyway and should be removed.