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 trialSpencer Renfro
Courses Plus Student 11,133 PointsCode challenge says my code is returning the wrong level
my code when ran produced all the right levels (ran creating other variables and using console.log). I am not sure why it is telling me it is returning the wrong level.
Below is the code I used to check the right levels:
class Student { constructor(gpa, credits){ this.gpa = gpa; this.credits = credits; }
// stringGPA() {
// return this.gpa.toString();
// }
get level()
{
if(this.credits <= 30){
return "they are a 'Freshman'";
}
if (this.credits >= 31 && this.credits < 61) {
return "they are a 'Sophmore'";
}
if (this.credits >= 61 && this.credits < 91) {
return "they are a 'Junior'";
}
if(this.credits > 90) {
return "they are a 'Senior'";
}
}
}
const student1 = new Student(3.9,29); const student2 = new Student(3.9,31); const student3 = new Student(3.9,60); const student4 = new Student(3.9,61); const student5 = new Student(3.9,91);
console.log(student1); console.log(student1.level); console.log(student2.level); console.log(student3.level); console.log(student4.level); console.log(student5.level);
class Student {
constructor(gpa, credits){
this.gpa = gpa;
this.credits = credits;
}
stringGPA() {
return this.gpa.toString();
}
get level()
{
if(this.credits <= 30){
return "they are a 'Freshman'";
}
if (this.credits >= 31 && this.credits < 61) {
return "they are a 'Sophmore'";
}
if (this.credits >= 61 && this.credits < 91) {
return "they are a 'Junior'";
}
if(this.credits > 90) {
return "they are a 'Senior'";
}
}
}
const student = new Student(3.9,60);
1 Answer
Steven Parker
231,269 PointsYou got a bit too fancy. The challenge is expecting just the one-word name of the level, not a whole sentence.
Also, there's a spelling error with 'Sophmore' (it should be 'Sophomore' with 3 "o"s).