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 trialHa Yeong Jeong
4,940 PointsWhy does my code work well in the web browser console but not on the challenge page?
It keeps giving an error saying the wrong level is given, but the code looks fine on the web console giving the correct outputs. Can you help and figure out what the issue is with my getter method?
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';
}
}
}
const student = new Student(3.9);
2 Answers
Steven Parker
231,275 PointsThe browser can't tell if your code meets the requirements, but the challenge will. For example, the instructions say "If the student has 90 or fewer credits, but more than 60 (>= 61
), they are a 'Junior'." So this means a student with 60 credits is not a Junior. But the code shown above will say "Junior" for anyone with 60 credits.
There is a similar issue with the limit for Sophomore.
Jason Anders
Treehouse Moderator 145,860 PointsYour conditionals for the second task are not quite right. For example, the second one states that they must have more than 60 credits, but your conditional will pass if they have only 60 credits and that is incorrect. If you have a look at the question again, the correct conditional is actually written right into the question itself. If you just change yours to match what the question states, the code will pass.
Nice work! :)
Jason Anders
Treehouse Moderator 145,860 PointsSteven types a bit faster than I it seems. Lol. :)
Steven Parker
231,275 PointsNot necessarily, I probably just logged in earlier.
Ha Yeong Jeong
4,940 PointsThank you. I appreciate your help.
Ha Yeong Jeong
4,940 PointsHa Yeong Jeong
4,940 PointsThank you so much!!!