Files
freeCodeCamp/curriculum/challenges/english/03-front-end-libraries/react/add-comments-in-jsx.md
Oliver Eyton-Williams 0bd52f8bd1 Feat: add new Markdown parser (#39800)
and change all the challenges to new `md` format.
2020-11-27 10:02:05 -08:00

82 lines
1.7 KiB
Markdown

---
id: 5a24bbe0dba28a8d3cbd4c5e
title: Add Comments in JSX
challengeType: 6
forumTopicId: 301376
---
# --description--
JSX is a syntax that gets compiled into valid JavaScript. Sometimes, for readability, you might need to add comments to your code. Like most programming languages, JSX has its own way to do this.
To put comments inside JSX, you use the syntax `{/* */}` to wrap around the comment text.
# --instructions--
The code editor has a JSX element similar to what you created in the last challenge. Add a comment somewhere within the provided `div` element, without modifying the existing `h1` or `p` elements.
# --hints--
The constant `JSX` should return a `div` element.
```js
assert(JSX.type === 'div');
```
The `div` should contain an `h1` tag as the first element.
```js
assert(JSX.props.children[0].type === 'h1');
```
The `div` should contain a `p` tag as the second element.
```js
assert(JSX.props.children[1].type === 'p');
```
The existing `h1` and `p` elements should not be modified.
```js
assert(
JSX.props.children[0].props.children === 'This is a block of JSX' &&
JSX.props.children[1].props.children === "Here's a subtitle"
);
```
The `JSX` should use valid comment syntax.
```js
assert(/<div>[\s\S]*{\s*\/\*[\s\S]*\*\/\s*}[\s\S]*<\/div>/.test(code));
```
# --seed--
## --after-user-code--
```jsx
ReactDOM.render(JSX, document.getElementById('root'))
```
## --seed-contents--
```jsx
const JSX = (
<div>
<h1>This is a block of JSX</h1>
<p>Here's a subtitle</p>
</div>
);
```
# --solutions--
```jsx
const JSX = (
<div>
<h1>This is a block of JSX</h1>
{ /* this is a JSX comment */ }
<p>Here's a subtitle</p>
</div>);
```