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 trialReagan Ganancial
9,476 Points2018 object oriented challenge
Your conditional statement is returning the wrong student level... I'am always getting this..
class Student {
constructor(gpa, credits){
this.gpa = gpa;
this.credits = credits;
}
get level () {
const credits = this.credits;
if (credits > 90) {
return 'senior';
} else if (credits > 61 && credits <= 90) {
return 'junior';
} else if (credits > 31 && credits <= 60) {
return 'sophomore';
} else {
return 'freshman';
}
}
}
const student = new Student(3.9);
6 Answers
Lee Geertsen
Java Web Development Techdegree Student 16,749 PointsJust putting this here:
class Student {
constructor(gpa, credits){
this.gpa = gpa;
this.credits = credits;
}
stringGPA() {
return this.gpa.toString();
}
get level() {
const credits = this.credits;
if(credits > 90) {
return "Senior";
} else if(credits > 60 && credits < 91) {
return "Junior";
} else if(credits > 30 && credits < 61) {
return "Sophomore";
}
return "Freshman";
}
}
trio-group I.AM
25,713 PointsYes. Because you're including the value 30 in the conditional for 'Sophomore' when it should be part of the 'Freshman' conditional. Change the value to 31 since you're now using the equals sign too.
Reagan Ganancial
9,476 PointsYehey! this one is correct and thank you very much!
trio-group I.AM
25,713 PointsHey!
Your code is omitting the values 31 and 61 because you are using the greater than operator. Switch 31 with 30 and 61 with 60 in your code and it should be valid.
Also sometimes workspaces is looking for an exact output and can be very specific about answers so if you're still having trouble try capitalizing the first letter of each string (as in the challenge instructions).
Hope this helps!
Reagan Ganancial
9,476 Pointsit still won't work;
class Student { constructor(gpa, credits){ this.gpa = gpa; this.credits = credits; }
stringGPA() {
return this.gpa.toString();
}
get level () {
const credits = this.credits;
if (credits > 90) {
return 'Senior';
} else if (credits > 61 && credits <= 90) {
return 'Junior';
} else if (credits > 30 && credits <= 60) {
return 'Sophomore';
} else {
return 'Freshman';
}
}
}
const student = new Student(3.9);
Elijah Quesada
Front End Web Development Techdegree Graduate 32,965 PointsYou could also just add two equal signs to make it greater than or equal.
class Student {
constructor(gpa, credits){
this.gpa = gpa;
this.credits = credits;
}
get level () {
const credits = this.credits;
if (credits > 90) {
return 'senior';
} else if (credits >= 61 && credits <= 90) {
return 'junior';
} else if (credits >= 31 && credits <= 60) {
return 'sophomore';
} else {
return 'freshman';
}
}
}
const student = new Student(3.9);
Reagan Ganancial
9,476 PointsSTILL NOT WORKING.. HUHUHU..
class Student {
constructor(gpa, credits){
this.gpa = gpa;
this.credits = credits;
}
stringGPA() {
return this.gpa.toString();
}
get level () {
const credits = this.credits;
if (credits > 90) {
return 'Senior';
} else if (credits >= 61 && credits <= 90) {
return 'Junior';
} else if (credits >= 30 && credits <= 60) {
return 'Sophomore';
} else {
return 'Freshman';
}
}
}
const student = new Student(3.9);
bviengineer
16,484 PointsI have tried my code in asending and decending order and is still receiving the message: "Your conditional is returning the wrong student level". See code:
get level(){ if(this.credits <=30){ return "Freshman"; } else if(this.credits >= 31 && this.credits <= 60){ return "Sophmore"; } else if(this.credits >= 61 && this.credits <= 90){ return "Junior"; } else if(this.credits >= 91){ return "Senior"; } }
get level(){ const credits = this.credits; if(this.credits >=91){ return "Senior"; } else if(this.credits >= 61 && this.credits <= 90){ return "Junior"; } else if(this.credits >= 31 && this.credits <= 60){ return "Sophmore"; } else if(this.credits >= 30){ return "Freshman"; } }
Lee Geertsen
Java Web Development Techdegree Student 16,749 PointsLee Geertsen
Java Web Development Techdegree Student 16,749 PointsWith between 31 and 60 they mean: bigger than 30 and smaller than 61 ;)