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 trialHilary Katsande
9,045 Pointsi can't get it
inside the getter method add a conditional statement
class Student {
constructor(gpa, credits){
this.gpa = gpa;
this.credits = credits;
}
get level() {}
const level = new Data();
const marks = level.getMarks();
if(student> 90 && student <= 90) {
return 'Senior';
} else {
return 'Junior';
return 'Freshman';
}
stringGPA() {
return this.gpa.toString();
}
}
const student = new Student(3.9);
2 Answers
Martin Lecke
14,385 PointsHi Im not sure what you are doing with new Data() and level.getMarks(). You might think of the Date() object. But its not needed for this exercise.
We want to return a String senior, junior etc. Depending how much credits they have. When we write this.credits
we get a number back saying how much credit they have. eg. 30
get level() {
if (this.credits > 90 ) { // if our credit is above 90 we want to do this
return 'Senior';
} else if (this.credits > 60) { // if our credit is above 60 we want to do this (if its above 90 the above will kick in first)
return 'Junior';
} else if (this.credits > 30) { // if our credit is above 30 we want to do this (if its above 60 the above will kick in first)
return 'Sophomore';
} else { // for the rest less than we want to return the string Freshman (this will be 30 and below)
return 'Freshman';
}
}
Hilary Katsande
9,045 Pointsthank you