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 trialJunior Suarez Peralta
Front End Web Development Techdegree Graduate 15,160 PointsThe getter method should return the level of a student, based on how many credits (this.credits) they have.
help, I dont know what I'm doing wrong
class Student {
constructor(gpa, credits){
this.gpa = gpa;
this.credits = credits;
}
stringGPA() {
return this.gpa.toString();
}
get level(){
let output ="";
if(this.credits => 90){ output + 'Senior';
}else if(this.credits <= 61 ){ output +'Junior';
}
}else if (this.credits <= 31 ){ output + 'sophomore';
}else( output += freshman
)
return output;
}
}
const student = new Student(3.9);
2 Answers
Fergus Clare
12,120 PointsA few observations.
- You invoke a new Student object, yet you are only passing one of the required values. You need the GPA and the Credits in order to successfully invoke a new Student object.
- Your get level method contains a space, which won't work. You'll need either
get_level()
orgetLevel()
- After you invoke the new Student object, you need to call the method on the object to return the level. For example:
const student = new Student(3.9, 64);
student.get_level();
- Your class method has an arrow function embedded in it which is incorrect.
=>
is attempting to read as an arrow or anonymous function. - You forget the += code in your assignment of the level, instead only using + operator.
Here is the revised code, which when provided with the gpa and credits, correctly returns the level:
class Student {
constructor(gpa, credits) {
this.gpa = gpa;
this.credits = credits;
}
stringGPA() {
return this.gpa.toString();
}
get_level() {
let output ="";
if (this.credits <= 90) { //removed arrow operator here
output += 'Senior'; //remember to use += instead of +
} else if (this.credits <= 61 ) {
output += 'Junior';
} else if (this.credits <= 31 ) {
output += 'sophomore';
} else {
output += 'freshman';
}
return output;}
}
const student = new Student(3.9, 94);
student.get_level();
>>> 'freshman' // this is clearly wrong, so work on the number logic for calculating level.
Fergus Clare
12,120 PointsHappy coding Junior Suarez Peralta! You got this!!!
Junior Suarez Peralta
Front End Web Development Techdegree Graduate 15,160 PointsJunior Suarez Peralta
Front End Web Development Techdegree Graduate 15,160 Pointsthank you very much