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 trialNas Jones
7,849 PointsUnanswered question
I watched the setter video before this and i was lost.
set owner(owner) { this._owner = owner; console.log(setter called: ${owner}); }
If you look at this code i see four different places where "owner" was used before it was logged in the console, why were they used in each instance?. I also don't understand why the "_" was necessary. Also, in this challenge i'm confused as well, all i got out of it was an if statement i don't know what to do further. Also, if this can be explained simply that would help me better instead of using complex words and code
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 > 60) {
return 'Junior';
} else if (this.credits > 30) {
return 'Sophomore';
} else {
return 'Freshman';
}
}
}
var student = new Student(3.9, 60);
1 Answer
Steven Parker
231,248 PointsIn your example, the setter method name is "owner", but the parameter passed to it is also named "owner". There is also a variable named "_owner" (the underscore is just part of the name). This is a common way to name variables that are used to hold the value passed in. A variable used and named this way is often called a "backing property".
It doesn't look like you've started any code yet, and none of these things apply to the first task of this challenge. But you will create a backing property when you get to task 2, along with some conditional code to implement the instructions.
Nas Jones
7,849 PointsNas Jones
7,849 PointsHello thank you for the help