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 trialZahra Toto
6,723 PointsWhat am I doing wrong:
I don't quite grasp the setter concept yet, so I don't see where my code goes wrong. Any help is welcome!
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';
}
}
/* If the student's level is Junior or Senior, the value of the backing property should be equal
to the parameter passed to the setter method. If the student is only a Freshman or Sophomore, set the "major"
backing property equal to 'None'. */
get major() {
return this._major;
}
set major(major) {
this._major = major;
if (major === 'Junior' || 'Senior'){
this._major = major
} else if (
major === 'Freshman' || 'Sophomore'){
this._major = 'None'
}
}
}
var student = new Student(3.9, 60);
3 Answers
Steven Parker
231,275 PointsYou are correct to put "this." in front of the backing property name.
But it should not be placed in front of the argument name.
Zahra Toto
6,723 PointsLike this? Still doesn't seem to work
set major(major) {
this._major = major;
if (major === 'Junior' || major === 'Senior' ){
this._major = major
} else if (
major === 'Freshman' || major === 'Sophomore' ){
this._major = 'None'
}
}
Steven Parker
231,275 PointsNow it has complete expressions, but the argument is still being compared with level names.
Zahra Toto
6,723 PointsOH I see what you mean!! That was a stupid mistake on my end. It worked, thanks so much!
Zahra Toto
6,723 PointsZahra Toto
6,723 PointsThanks for your reply! I changed it, still doesn't work unfortunately =(
Steven Parker
231,275 PointsSteven Parker
231,275 PointsIt looks like you made some extra changes. I don't recall precisely what you had before but now I see some additional issues: