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 trialElijah Sellers
Full Stack JavaScript Techdegree Student 7,785 PointsI'm not seeing where my conditional statements are wrong? when i run it normally in VS code it runs fine
Per the title. I'm not understanding why my code isnt working anyhelp would be great!
class Student {
constructor(gpa, credits){
this.gpa = gpa;
this.credits = credits;
}
get level() {
if ( this.credit > 90 ) {
return 'Senior';
} else if ( this.credit <= 90 && this.credit >= 61 ) {
return 'Junior';
} else if ( this.credit <= 60 && this.credit >= 31 ) {
return 'Sophomore';
} else {
return 'Freshman'
}
}
stringGPA() {
return this.gpa.toString();
}
}
const student = new Student(3.9);
2 Answers
Steven Parker
231,269 PointsVery odd that VS Code did not detect the error!
The logic is good, but the name of the attribute should be "credits" (plural) instead of "credit" (singular).
Shawn Lindsey
20,952 PointsAwesome, thanks for the response.
Shawn Lindsey
20,952 PointsShawn Lindsey
20,952 PointsYou seem to really know your stuff, so I was curious if there was a reason or any kind of gotcha that should discourage me from formulating my code as follows (this passed the challenge, fwiw):
get level() { if ( this.credit > 90 ) { return 'Senior'; } else if ( this.credit >= 61 ) { return 'Junior'; } else if ( this.credit >= 31 ) { return 'Sophomore'; } else { return 'Freshman'; } }
In other words, it seemed to me that you don't need to get explicit with the middle ranges since it's implied that credit ranges above have already been covered by the logic of the "else if". Hopefully that makes sense; I couldn't think of a better way to put it.
Steven Parker
231,269 PointsSteven Parker
231,269 PointsYou're quite right, the high end of the range need not be checked since it would have been handled by the previous test.