question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Possibe error in code example

See original GitHub issue

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

https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/using-objects-for-lookups


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.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:16 (14 by maintainers)

github_iconTop GitHub Comments

1reaction
jeremyltcommented, Nov 7, 2022

I like that example better. I think we should use it + the corresponding text fixes that would be needed.

1reaction
Sboonnycommented, Nov 6, 2022

Yeah, the numerical index is odd.

Does it have to be an alphabet? Is there a better, simpler example?

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.

const article = {
  "title": "How to create objects in JavaScript",
  "link": "https://www.freecodecamp.org/news/a-complete-guide-to-creating-objects-in-javascript-b0e2450655e8/",
  "author": "Kaashan Hussain",
  "language": "JavaScripts",
  "tags": "TECHNOLOGY",
  "createdAt": "NOVEMBER 28, 2018"
};

const articleAuthor = article[author];
const articleLink = article[link];

const value = "title";
const valueLookup = article[value];
Read more comments on GitHub >

github_iconTop Results From Across the Web

The 7 Most Common Types of Errors in Programming and ...
Resource errors are an example of a type of error in programming that might be something for the operations team to fix rather...
Read more >
Incorrect program example: Using the error code parameter
The error code parameter provides a way for you to determine whether an API encounters any errors. Here are the program examples that...
Read more >
7 Common Programming Errors | Remote Coding in San Diego
1. Runtime errors. These bugs occur when the code “won't play nice” with another computer, even if it worked perfectly fine on the...
Read more >
Errors and exceptions - Object-Oriented Programming in Python
Here are some examples of syntax errors in Python: myfunction(x, y): return x + y else: ... Find potential sources of runtime errors...
Read more >
Types of Errors in Java with Examples - GeeksforGeeks
Error is an illegal operation performed by the user which results in the abnormal working of the program. Programming errors often remain ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found