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 trialAbson Chifodya
11,817 PointsInside the getter method use the conditional statement of your choice to determine the level of the student. If the valu
Inside the getter method use the conditional statement of your choice to determine the level of the student. If the value of the "credits" property is over 90, return 'Senior'. If it's between 61 and 90, return 'Junior'. If it's between 31 and 60, return 'Sophomore'. If it's 30 or less, return 'Freshman'.
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 (credits >= 61 && credits <= 90 )
return Junior
else if (credits >= 31 && credits <= 60)
return Sophomore
else (credits <= 30 )
return Freshman
}
}
const student = new Student(3.9);
3 Answers
Adam Beer
11,314 PointsFirst, fixed the curly brackets, semicolons, pharagraphs and inside the first and second else if you delete the second statement both of them.
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';
}
}
Mike Lundahl
13,510 PointsThis doesn't work for me either. I tested my code in the workspace and the code runs with no errors there with expected results.. But for some reason not in the course? My code looks similar to the above but I added:
const student = new Student(3.9, 50);
console.log(student.level);
Michael Pashkov
22,024 PointsHi, in the first place - = 90 in both statements - get level() { if (this.credits >= 90 ) { return Senior }else if (credits >= 61 && credits <= 90 ). second - curly bracket "{}" - take a notice. And - " ' " , ";", "this.". Look how I did this.
class Student { constructor(gpa, credits){ this.gpa = gpa; this.credits = credits; }
get level() {
if (this.credits > 90) {
return 'Senior';
} else if (this.credits >= 61 && this.credits <= 90) {
return 'Junior';
} else if (this.credits >= 31 && this.credits <= 60) {
return 'Sophomore';
} else {
return 'Freshman';
}
}
stringGPA() {
return this.gpa.toString();
}
}
const student = new Student(3.9);
Salma Yarista
4,595 PointsSalma Yarista
4,595 PointsIn the 1st and 2nd else if statements, you have to edit the credits to this.credits. This is to select the credits inside the Student Class. And as for the last conditional (else), the rule of credits <= 30 does not necessarily need to be written.
Other corrections should be made to the typos: parentheses, curly bracket, semicolon, and single/double quotes. I suppose that being meticulous is a must when writing codes.
This is how I completed the challenge: