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.

Add Comments in JSX

See original GitHub issue

Describe your problem and how to reproduce it: On the “React: Add Comments in JSX” page instructions are: “Add a comment somewhere within the provided div element, without modifying the existing h1 or p elements.”

And So I entered

const JSX = (
  <div> {/*test*/}
    <h1>This is a block of JSX</h1>
    <p>Here's a subtitle</p>
  </div>
);

This doesn’t affect the h1 or p tags, and yet it fails to pass the test.

Add a Link to the page with the problem: https://learn.freecodecamp.org/front-end-libraries/react/add-comments-in-jsx

Tell us about your browser and operating system:

  • Browser Name: Chrome
  • Browser Version: Latest
  • Operating System: MacOSX

If possible, add a screenshot here (you can drag and drop, png, jpg, gif, etc. in this box): image

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
richb999gitcommented, Dec 17, 2018

Like this:

  • text: The div should contain an h1 tag as the first element. testString: assert(JSX.props.children[0].type === ‘h1’ || JSX.props.children[1].type === ‘h1’, ‘The div should contain an h1 tag as the first element.’);
  • text: The div should contain a p tag as the second element. testString: assert(JSX.props.children[1].type === ‘p’ || JSX.props.children[2].type === ‘p’ || JSX.props.children[3].type === ‘p’, ‘The div should contain a p tag as the second element.’);

In the challenge files (this is the English version): \freeCodeCamp\curriculum\challenges\english\03-front-end-libraries\react\add-comments-in-jsx.english.md

1reaction
richb999gitcommented, Dec 17, 2018

It appears that if you add a comment on the same line as a tag with a space before it it adds it as a child. This means the tests then are looking at the wrong children. If you add a comment on a new line it’s ok. If you add a comment after a tag without a space between the tag and the comment it’s ok. I think you could test for h1 tag being child 0 or 1 and p tag being child 1, 2 or 3. Is that an acceptable test?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to comment in React JSX - Wes Bos
If you use Sublime Text, I've created a little snippet so you can just type jc + TAB to get a quick comment....
Read more >
React Native Comments - 2 Ways to Add Comments in JSX
If you want to comment a single line then you can use Double Forward Slash(//) but it can only be used outside of...
Read more >
How to use comments in React - Stack Overflow
Within React(JSX), you can use {/* comment here */} , however for javascript // comment here works. So, the answer depends on where...
Read more >
FreeCodeCamp/add-comments-in-jsx.english.md at master
JSX is a syntax that gets compiled into valid JavaScript. Sometimes, for readability, you might need to add comments to your code.
Read more >
How to write comments in React and JSX - Nathan Sebhastian
To write comments in JSX, you need to use JavaScript's forward-slash and asterisk syntax, enclosed inside a curly brace {/* comment here */}...
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