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 trialAdam Dickerson
1,618 PointsWhat am I doing wrong? 'Bummer: Your conditional statement is returning the wrong student level.'
Not sure what is wrong with the code. I've checked the other questions and it seems like the code is in line with what people have said to fix.
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 <= 90 && this.credits >= 61) {
return 'Junior';
} else if (this.credits <= 60 && this.credits >= 31) {
return 'Sophmore';
} else if (this.credits <= 30) {
return 'Freshman';
}
}
}
const student = new Student(3.9);
3 Answers
Andrew Hinkson
Full Stack JavaScript Techdegree Graduate 25,822 PointsEverything looks good except you may check your spelling on your student levels.
Lee Nolan
21,690 PointsAlso, whilst not technically incorrect, you do not need the final 'else if' comparison...you can just do;
else { return 'Freshman'; }
This is because junior/senior/sophomore have already evaluated as false, so freshman is the only possible outcome by now.
Michael Kroon
16,255 PointsLee is correct in that you technically don't need that last 'else if'. You can use a simple 'else' since it's the final condition. It'll still run...
I also checked Andrew's suggestion but the name of the getter is correct...
The problem was in your spelling of 'Sophomore'. Your code has 'Sophmore', so it wasn't returning the correct string if the credits variable was sit to between 31 and 60...
So after I corrected the spelling, it worked. :)