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 trialKhumoyunmirzo Nosirov
8,689 PointsI couldn't find the error , pls help What is wrong here
Inside the major() setter method, set the student's major to a backing property "_major". 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'.
class Student {
constructor(gpa, credits){
this.gpa = gpa;
this.credits = credits;
}
stringGPA() {
return this.gpa.toString();
}
set major(major) {
this._major = major;
if(major === "Senior" || major === "Junior")
{
this._major = major;
}
else if(major === "Sophomore" || major === "Freshman")
{
this._major = "None";
}
}
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);
2 Answers
Kristoffer A-L
5,863 PointsHi,
I had some issues with this one as well. I posted my code below. You need to change "major" in the if-statement to this.level. I think you will also need the get major().
get major() {
this._major = major;
}
set major(major) {
this._major = major;
if (this.level === 'Junior' || this.level === 'Senior') {
this._major = major;
} else if (this.level === 'Freshman' || this.level === 'Sophomore') {
this._major = 'None';
}
}
KRIS NIKOLAISEN
54,972 PointsOne of the things you can do is paste your code into a workspace to see if you get a better error message. Unexpected identifier without a line number can take some time. But in a workspace it shows you it is at line 23 just above get level(). There is an extra closing bracket at this location.
For task 2 you will want to check the level to set the major.
Khumoyunmirzo Nosirov
8,689 Points"Your setter method is returning the wrong value for the major property."
when I tried it says this