Challenge Waypoint: Make Object Properties Private has an issue.
I've noticed that we're getting a lot of questions on this one in the help channels and elsewhere. Vast majority of campers who are asking just don't know what to do at all. This either needs a massive rewrite or to be broken out into several waypoints.
I think the issue is that there are too many new concepts introduced with no practical explanation. There is no example code showing var privateProperty
.
Currently doing a pass through basic javascript for typos and style issues but I'd be happy to take a look at this tonight or tomorrow if no one else does before then.
I just opened an issue #4178 that suggests a change to the instructions. I think the curriculum needs to be modified as a whole (for this area), but the instruction change could be useful. I was slow to write my change so I didn't notice SainPeter had opened an issue
@MattYamamoto I like your proposed changes, but I think that we need to specifically give sample code.
@ltegman Long term I anticipate doing a complete rewrite and expansion of the whole section, but for the short term I think we need something to reduce the number of questions we're getting on this specific waypoint.
Maybe between you two we can come up with a quick fix and I'll add this to my longer term list.
For reference here, here was the suggested change to the instructions:
I have addressed a number of questions regarding this Waypoint over that past week. While I don't believe the wording of the instructions is to blame for all the confusion, perhaps some clarity could be added at the end to help users understand what needs to be done while also reinforcing the terminology. Additions in bold, deleted text struck through.
Properties Private
Objects have their own attributes, called properties, and their own functions, called methods.
In the previous challenge, we used the this keyword to reference public properties and public methods of the current object.
We can also create private properties and private methods, which aren't accessible from outside the object.
To do this, just declare properties or functions within the constructor without the
this
keyword.
Let's create an object with two functions. One attached as a property and one not.
See if you can keep myBike.speed and myBike.addUnit private, while making myBike.getSpeed publicly accessible.
See if you can modify the Bike constructor so that both the speed property and the addUnit method are private, while also making the getSpeed method publicly accessible for all objects created from the Bike constructor. We'll check your work by testing the myBike object we've created from the Bike constructor at the bottom of the code.
I like your thinking @SaintPeter, dividing that section up into two, perhaps implementing a 'review' section at the end to prepare for the 'basic algorithms'.
I'm having trouble with this one, also. My issue(s) are threefold:
1) You explain that public properties and methods need to have "this." in front of them, but you don't clarify that private ones need to have "var" in front of them.
2) You fail to explain the difference in syntax between the definition of the "getUnit" and "addSpeed" functions in the "Bike" function, and why simply slapping "this." onto both of those whenever they appear doesn't work.
3) You can't tell us to do something (e.g. put "this." on a property or function to make it public), and then throw us a case where it doesn't apply, without explaining the "why" and "how" fully.
Thanks!
While I appreciate that the rewrite for this Waypoint reads more coherently, it is no more helpful than the last iteration in terms of clarifying syntax and instructions. To wit:
1) We have not yet been taught how to create methods inside of a constructor; we have only been taught how to create properties.
2) We have not yet been taught how to combine the "this" keyword with methods constructed inside a constructor.
3) We have not been given any parameters or arguments for the methods we're supposed to create inside the instructor.
It seems like whoever did the rewrite did not look at this Waypoint in the context of the instructions we've received so far. There are still all sorts of gaps in logic and steps and syntax that haven't been explained yet, and I don't know enough about what those are to even name them.
Programmers are supposed to be good at breaking tasks down into their smallest component steps. Can someone please use the same logic here, and start from the mind of a beginner?
@gitasong Both @ltegman and I are in complete agreement with you. This whole sequence of waypoints could use some serious love and attention. @ltegman 's rewrite was intended as a stopgap only, until we have time do do a more comprehensive rewrite of the whole section.
It sounds like you have strong ideas about how that should be accomplished and you are a clear and effective communicator. If you would like to propose an outline for this series of challenges, or even write them, we would almost certainly use your work.
Here is an example of the high level outline I'm working on for the Basic Javascript revamp. At this time I'm waiting for some infrastrucure and tooling changes to implement it. If you wanted to produce a similar outline for the OO curriculum, just titles and notes on content, @ltegman and I could take it and run with it. Or if you're feeling up to you, you could even take a stab at writing the content.
Programmers are supposed to be good at breaking tasks down into their smallest component steps. Can someone please use the same logic here, and start from the mind of a beginner?
I will say this - it's harder than it looks. :smile: If it was easy, we'd be "done" already. FCC is open source for a reason - so we can take the best our campers have to offer and feed it back into our curriculum. Not that we'll ever truely be done . . . we're trying to hit a moving target.
We'd really appreciate any help you can give us.
@SaintPeter : Appreciate the kindness and the listening in your response. When I ask for help on Gitter, I often feel like I'm shouting into the wind.
Unfortunately, while I know how to break things down into logical steps and know what good teaching looks like, I just don't know enough about programming to do what you ask. It would be a little like asking someone to write a calculus curriculum who's just learning arithmetic. :) I could, however, test-drive anything you write, and tell you if it makes sense from the standpoint of a (near-) total beginner, and also to tell you what gaps I see in the instructions and/or explanations. :)
@SaintPeter Taking a look at your outline and combining it with my issues around this Waypoint, it might be useful to have a whole section on creating object methods using JSON. There's been very little taught on functions so far, and if functions (i.e. methods) are able to be valid parts of objects, there ought to be some instruction on how to write, create, and use these.
@gitasong I think we're on the same page. What you're describing is pretty much what we're envisioning. We just need to . . . you know . . have the time to implement it. If this is something you're interested in, we have occasional discussions in the CurriculumDevelopment Chat Room.
@SaintPeter I've joined. Feel free to ping me any time you need newbie testing. :)
For the record, one thing I'm really good at is seeing gaps--in logic or completeness. And if the problem is simple enough, I'm usually able to articulate what those gaps are--at least, in English. So feel free use me for that. :)
Im very frustrated and disappointed with FCC.
It is very poor teaching website. No explanation, no introduction, only 1 useless example, unrelated test to example. If the creators are thinking that campers will learn by themselves by learning elsewhere, they did not even bother including resources where campers can learn the basic lesson.
I've studied w3school before FCC, and I did not learn a single thing from here. I am now on Make Object Properties Private and I have no idea what this subject is discussing.
FCC teaches very little compared to w3school. Its 10x worse than codeacademy.
FCC has been great up to this point, but on this one course I am completely stuck! I feel like there is a lot missing here.
I come from a language where if you are initializing a variable it has to be to something, the entire notion of being able to accomplish "var gear;" and it automatically be set to undefined was foreign to me. Initially I did:
var Bike = function() {
// Only change code below this line.
var gear = undefined;
this.getGear = function() {
return gear;
};
this.setGear = function(newGear) {
gear = newGear;
};
};
Despite the FCC editor alerting me to the fact that I didnt have to set gear to undefined.
I later refactored my code to get "var gear" to clear the alert raised by the editor. Again, to me it hasnt really been mentioned that you can successfully initialize a var without setting to anything....coming from Ruby such a concept doesnt even exist I dont think. This is what lead to my confusions at least.
var Bike = function() {
// Only change code below this line.
var gear;
this.getGear = function() {
return gear;
};
this.setGear = function(newGear) {
gear = newGear;
};
};
I'm not clear why this issue has been closed -- just as I am unclear on everything I've been trying to learn in the _Object Oriented and Functional Programming_ section. The style, format, and language of the explanations/instructions differ vastly from those I've encountered so far.
I understand that FCC culture encourages campers to google/research independently when stuck and then ask for help. I've been reading Douglas Crockford's article _Private Members in JavaScript_. Douglas' article is significantly more clear in explaining both the concept of private variables and methods. However, every third word in his piece made me need to google something (while this was very informative, it was time consuming, inefficient and unbelievably tangential). Nonetheless, I imagine Crockford's work might serve as a good starting point for reworking this section.
The shift in language, format, and style between the _Basic Javascript_ section and the _Object Oriented Programming_ sections aside. There is a significant gap in understanding that's created between the two sections. I am left feeling that there is some implicit learning that happened in CS degree classes somewhere that never made it into Codecamp. Are there primers I can read to soften this leap?
@manicmarvin Frankly, many of these challenges need to be re-written. I don't think they will seem all that complicated if we do a better job of explaining them.
var Bike = function() {
// Only change code below this line.
var gear=0;
this.setGear=function(change){
gear=change;
};
this.getGear=function()
{
return gear;
};
};
i got this code passed...bassically we are setting /change/ value in the private /gear/ variable using setGear method and then returning through getGear method.
Most helpful comment
@manicmarvin Frankly, many of these challenges need to be re-written. I don't think they will seem all that complicated if we do a better job of explaining them.