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 trialMikel Cati
8,045 Points!set and get!
Hello,
I am trying to understand when we set out the parameter holds the value of this._out which is false and then we set this._out = out (im really confused because if out(the parameter) holds already the value of this._out which is already false its like we
re saying this._out(false) = out(false) . And also at the conditional if(out) <= (means that if out is false (which will return true because out is indeed false) run the code?)
What if i did this.... ///this out = false; if(!out) // if out is not false{ /* run the code */ }
1 Answer
Doron Geyer
Full Stack JavaScript Techdegree Student 13,897 PointsHi Mikel Cati , its quite easy to get confused here. The reason is the use of the word out as the parameter which I think they do to maintain continuity with how they have been teaching getters and setters.
set out(out){
this._out = out;
if (out) {
const newDueDate = new Date();
newDueDate.setDate(newDueDate.getDate() + 14);
this.dueDate = newDueDate;
} else {
this.dueDate = null;
}
}
so what I did to make this a little clearer is just change that word to something that would make more sense to you , read through this and see if it helps you get a better idea of whats happening.
set out(trueOrFalse){
this._out = trueOrFalse;
if (true) {
const newDueDate = new Date();
newDueDate.setDate(newDueDate.getDate() + 14);
this.dueDate = newDueDate;
} else {
this.dueDate = null;
}
}
you will see if you change those names in your code it still works as intended but its a little easier to understand whats actually happening.
If this answer helped resolve your question please select best answer to close this off.
cheers, Doron