2.9 KiB
2.9 KiB
id, title, challengeType, videoUrl, localeTitle
id | title | challengeType | videoUrl | localeTitle |
---|---|---|---|---|
56533eb9ac21ba0edf2244b4 | Quoting Strings with Single Quotes | 1 | 单引号引用字符串 |
Description
doubleQuoteStr =“这是一个字符串”;你可能想要使用一种报价而不是另一种报价的原因是你想在字符串中使用这两种报价。如果要将对话保存在字符串中并将对话用引号括起,则可能会发生这种情况。它的另一个用途是在一个字符串中保存带引号中各种属性的
singleQuoteStr ='这也是一个字符串';
<a>
标签。 谈话='芬恩向杰克惊呼,“代数!”';但是,如果您需要使用其中的最外层引号,这将成为一个问题。请记住,字符串在开头和结尾都有相同的引用。但是如果你在中间的某个地方有相同的引用,字符串将提前停止并抛出错误。
goodStr ='杰克问芬恩,“嘿,我们去冒险吧?”在上面的goodStr中 ,您可以使用反斜杠
badStr ='芬恩回答,“我们走了!”'; //引发错误
\
作为转义字符安全地使用两个引号。 注意 反斜杠
\
不应与正斜杠/
混淆。他们不做同样的事情。 Instructions
<a>
标签在任何地方都使用双引号。您需要将外引号更改为单引号,以便删除转义字符。 Tests
tests:
- text: 删除所有<code>backslashes</code> ( <code>\</code> )
testString: 'assert(!/\\/g.test(code) && myStr.match("\\s*<a href\\s*=\\s*"http://www.example.com"\\s*target\\s*=\\s*"_blank">\\s*Link\\s*</a>\\s*"), "Remove all the <code>backslashes</code> (<code>\</code>)");'
- text: '你应该有两个单引号<code>'</code>和四个双引号<code>"</code>'
testString: 'assert(code.match(/"/g).length === 4 && code.match(/"/g).length === 2, "You should have two single quotes <code>'</code> and four double quotes <code>"</code>");'
Challenge Seed
var myStr = "<a href=\"http://www.example.com\" target=\"_blank\">Link</a>";
After Test
console.info('after the test');
Solution
// solution required