* feat(tools): add seed/solution restore script * chore(curriculum): remove empty sections' markers * chore(curriculum): add seed + solution to Chinese * chore: remove old formatter * fix: update getChallenges parse translated challenges separately, without reference to the source * chore(curriculum): add dashedName to English * chore(curriculum): add dashedName to Chinese * refactor: remove unused challenge property 'name' * fix: relax dashedName requirement * fix: stray tag Remove stray `pre` tag from challenge file. Signed-off-by: nhcarrigan <nhcarrigan@gmail.com> Co-authored-by: nhcarrigan <nhcarrigan@gmail.com>
2.3 KiB
2.3 KiB
id, title, challengeType, videoUrl, forumTopicId, dashedName
id | title | challengeType | videoUrl | forumTopicId | dashedName |
---|---|---|---|---|---|
56533eb9ac21ba0edf2244b4 | 用单引号引用字符串 | 1 | https://scrimba.com/c/cbQmnhM | 18260 | quoting-strings-with-single-quotes |
--description--
JavaScript 中的字符串可以使用开始和结束都是同类型的单引号或双引号表示,与其他一些编程语言不同的是,单引号和双引号的功能在 JavaScript 中是相同的。
doubleQuoteStr = "This is a string";
singleQuoteStr = 'This is also a string';
当你需要在一个字符串中使用多个引号的时候,你可以使用单引号包裹双引号或者相反。常见的场景比如在字符串中包含对话的句子需要用引号包裹。另外比如在一个包含有<a>
标签的字符串中,<a>
标签的属性值需要用引号包裹。
conversation = 'Finn exclaims to Jake, "Algebraic!"';
但是,如果你想在字符串中使用与最外层相同的引号,会有一些问题。要知道,字符串在开头和结尾都有相同的引号,如果在中间使用了相同的引号,字符串会提前中止并抛出错误。
goodStr = 'Jake asks Finn, "Hey, let\'s go on an adventure?"';
badStr = 'Finn responds, "Let's go!"'; // Throws an error
在上面的goodStr
中,通过使用反斜杠\
转义字符可以安全地使用两种引号 提示
不要把反斜杠\
和斜杠/
搞混,它们不是一回事。
--instructions--
把字符串更改为开头和结尾使用单引号的字符串,并且不包含转义字符。
这样字符串中的<a>
标签里面任何地方都可以使用双引号。你需要将最外层引号更改为单引号,以便删除转义字符。
--hints--
删除所有反斜杠
(\
)。
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*'
)
);
应该要有两个单引号'
和四个双引号"
。
assert(code.match(/"/g).length === 4 && code.match(/'/g).length === 2);
--seed--
--after-user-code--
(function() { return "myStr = " + myStr; })();
--seed-contents--
var myStr = "<a href=\"http://www.example.com\" target=\"_blank\">Link</a>";
--solutions--
var myStr = '<a href="http://www.example.com" target="_blank">Link</a>';