freeCodeCamp/curriculum/challenges/chinese/02-javascript-algorithms-an.../debugging/catch-mixed-usage-of-single...

2.2 KiB
Raw Blame History

id title challengeType videoUrl localeTitle
587d7b84367417b2b2512b37 Catch Mixed Usage of Single and Double Quotes 1 抓住单引号和双引号的混合使用

Description

JavaScript允许使用单个和双”“引号来声明一个字符串。决定使用哪一个通常归结为个人偏好但有一些例外。当字符串有收缩或另一个时有两个选择很好引号中的文本片段。请注意不要过早关闭字符串这会导致语法错误。以下是混合引号的一些示例
//这些是正确的:
const grouchoContraction =“我度过了一个美好的夜晚,但事实并非如此。”;
const quoteInString =“Groucho Marx曾经说过'引用我的话说我被误引了'。”;
//这是不正确的:
const uhOhGroucho ='我度过了一个美妙的夜晚,但这不是它。';
当然,只使用一种报价样式是可以的。您可以使用反斜杠(\)转义字符来转义字符串中的引号:
//正确使用相同的引号:
const allSameQuotes ='我度过了一个非常精彩的夜晚,但这不是它。';

Instructions

修复字符串,使其对href值使用不同的引号,或者转义现有的引号。在整个字符串周围保留双引号。

Tests

tests:
  - text: '您的代码应该通过更改或转义它们来修复<code>href</code>值“#Home”周围的引号。'
    testString: 'assert(code.match(/<a href=\s*?("|\\")#Home\1\s*?>/g), "Your code should fix the quotes around the <code>href</code> value "#Home" by either changing or escaping them.");'
  - text: 您的代码应该在整个字符串周围保留双引号。
    testString: 'assert(code.match(/"<p>.*?<\/p>";/g), "Your code should keep the double quotes around the entire string.");'

Challenge Seed

let innerHtml = "<p>Click here to <a href="#Home">return home</a></p>";
console.log(innerHtml);

Solution

// solution required