freeCodeCamp/curriculum/challenges/chinese/03-front-end-libraries/react/add-comments-in-jsx.chinese.md

2.0 KiB
Raw Blame History

id title challengeType isRequired videoUrl localeTitle
5a24bbe0dba28a8d3cbd4c5e Add Comments in JSX 6 false 在JSX中添加注释

Description

JSX是一种可以编译成有效JavaScript的语法。有时为了便于阅读您可能需要在代码中添加注释。像大多数编程语言一样JSX有自己的方法来做到这一点。要将注释放在JSX中可以使用语法{/* */}来包含注释文本。

Instructions

代码编辑器的JSX元素与您在上一个挑战中创建的元素类似。在提供的div元素中的某处添加注释,而不修改现有的h1p元素。

Tests

tests:
  - text: 常量<code>JSX</code>应该返回一个<code>div</code>元素。
    testString: 'assert(JSX.type === "div", "The constant <code>JSX</code> should return a <code>div</code> element.");'
  - text: <code>div</code>应包含一个<code>h1</code>标记作为第一个元素。
    testString: 'assert(JSX.props.children[0].type === "h1", "The <code>div</code> should contain an <code>h1</code> tag as the first element.");'
  - text: <code>div</code>应该包含一个<code>p</code>标签作为第二个元素。
    testString: 'assert(JSX.props.children[1].type === "p", "The <code>div</code> should contain a <code>p</code> tag as the second element.");'
  - text: <code>JSX</code>应该包含一条评论。
    testString: 'getUserInput => assert(getUserInput("index").includes("/*") && getUserInput("index").includes("*/"), "The <code>JSX</code> should include a comment.");'

Challenge Seed

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

After Test

console.info('after the test');

Solution

// solution required