freeCodeCamp: Possibe error in code example
Describe the Issue
The example shows “const thirdLetter = alpha[2]”. Below that, the snippet of text says that alpha[2] should be “Y”. “thirdLetter is the string Y, lastLetter is the string C, and valueLookup is the string Y.”
Affected Page
const alpha = {
1:"Z",
2:"Y", //<--------------- thirdLetter ??
3:"X",
4:"W",
...
24:"C", //<--------------- lastLetter ??
25:"B",
26:"A"
};
const thirdLetter = alpha[2];
const lastLetter = alpha[24];
const value = 2;
const valueLookup = alpha[value];
The snippet has the below explanation in the instructions:
`thirdLetter` is the string `Y`, lastLetter is the string `C`, and `valueLookup` is the string `Y`.
Expected behavior
I believe correcting the const “thirdLetter” to “secondLetter” could be less confusing.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 16 (14 by maintainers)
I like that example better. I think we should use it + the corresponding text fixes that would be needed.
I can’t think of a better example to be honest, but we can use a practical one. Like how the freeCodeCamp codebase Json files structured.
The variable name in current example is plain wrong. Nobody said that was not the case.
Nothing is forcing us to use 1 based indexing here. Personally, in addition to fixing the variable name, I would use 0 based indexing.
However, I’m thinking this object should be replaced with a simpler object. That would increase clarity and remove the strange indexing.
We’re discussing how to fix the problem. Everyone seems to agree that the problem exists.
Yes, we need to wait. The issue isn’t ready for contributions when discussion is ongoing.
Yes, I understand how objects work. I don’t see a reason to start counting at 1 here when in general JS starts counting at 0.