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 trialMary Pienzi
Full Stack JavaScript Techdegree Student 7,036 PointsOOP getter methods: returning "unexpected token >" Usually this means I have a syntax error, but I'm not sure.
It's just a syntax problem right? If that's the case then i should be able to see it.
class Student {
constructor(gpa, credits){
this.gpa = gpa;
this.credits = credits;
}
stringGPA() {
return this.gpa.toString();
}
get level(){
switch(this.credits){
case > 90:
return "Senior";
break;
case >= 61:
return "Junior";
break;
case >= 31:
return "Sophomore";
break;
case < 31:
return "Freshman";
break;
}
}
const student = new Student(3.9, 54);
2 Answers
Mary Pienzi
Full Stack JavaScript Techdegree Student 7,036 PointsYes, need to read the instructions carefully and get the correct values before implosion.
Thanks.
Steven Parker
231,248 PointsThe cases in a "switch" statement need to have values that will be compared to the switch argument. The "case" itself is not a variable or parameter.
For more details on proper usage and syntax, see the MDN page for switch.
Since this function involves value ranges instead of specific values, an "if/else if" chain might be more useful than a "switch".
Mary Pienzi
Full Stack JavaScript Techdegree Student 7,036 PointsThanks for the tip. I changed it to an if/else if chain but its now coming back with "Your conditional statement is returning the wrong student"
Now when I run the exact same code in a browser it returns the expected value.
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 >= 61 && this.credits < 90){
return "Junior";
}else if(this.credits >= 31 && this.credits < 61){
return "Sophomore";
}else{
return "Freshman";
}
}
}
const student = new Student(3.9, 93);
WHAT am I missing?
Steven Parker
231,248 PointsThe instructions say "If the student has 90 or fewer credits ... they are a 'Junior'."
But this code considers 90 credits to be a "Senior".
Steven Parker
231,248 PointsSteven Parker
231,248 PointsMary Pienzi — Did you mean to mark your own comment as "best answer"?
(You can still change it)