3.1 KiB
3.1 KiB
id, challengeType, videoUrl, forumTopicId, localeTitle
id | challengeType | videoUrl | forumTopicId | localeTitle |
---|---|---|---|---|
56533eb9ac21ba0edf2244b6 | 1 | https://scrimba.com/c/cvmqRh6 | 17567 | 字符串中的转义序列 |
Description
代码 | 输出 |
---|---|
\' | 单引号 |
\" | 双引号 |
\\ | 反斜杠 |
\n | 换行符 |
\r | 回车符 |
\t | 制表符 |
\b | 退格 |
\f | 换页符 |
Instructions
myStr
。
FirstLine你需要使用转义字符正确地插入特殊字符,确保间距与上面文本一致并且单词或转义字符之间没有空格。 像这样用转义字符写出来:
\SecondLine
ThirdLine
FirstLine换行符
制表符
反斜杠
SecondLine换行符
ThirdLine
Tests
tests:
- text: <code>myStr</code>不能包含空格。
testString: assert(!/ /.test(myStr));
- text: <code>myStr</code>应该包含字符串<code>FirstLine</code>, <code>SecondLine</code> and <code>ThirdLine</code> (记得区分大小写)。
testString: assert(/FirstLine/.test(myStr) && /SecondLine/.test(myStr) && /ThirdLine/.test(myStr));
- text: <code>FirstLine</code>后面应该是一个新行<code>\n</code>。
testString: assert(/FirstLine\n/.test(myStr));
- text: <code>myStr</code>应该包含制表符<code>\t</code>并且制表符要在换行符后面。
testString: assert(/\n\t/.test(myStr));
- text: <code>SecondLine</code>前面应该是反斜杠<code>\\</code>。
testString: assert(/\SecondLine/.test(myStr));
- text: <code>SecondLine</code>和<code>ThirdLine</code>之间应该是换行符。
testString: assert(/SecondLine\nThirdLine/.test(myStr));
- text: <code>myStr</code> 应该只包含介绍里面展示的字符串。
testString: assert(myStr === 'FirstLine\n\t\\SecondLine\nThirdLine');
Challenge Seed
var myStr; // Change this line
After Test
(function(){
if (myStr !== undefined){
console.log('myStr:\n' + myStr);}})();
Solution
var myStr = "FirstLine\n\t\\SecondLine\nThirdLine";