Merge pull request #9229 from erictleung/fix/improve-escape-character-sequence

Clarify Escape Sequences in Strings challenge
pull/9248/head
Stuart Taylor 2016-06-19 23:25:13 +01:00 committed by GitHub
commit a24e07105c
1 changed files with 12 additions and 4 deletions

View File

@ -1036,10 +1036,14 @@
"title": "Escape Sequences in Strings",
"description": [
"Quotes are not the only characters that can be <dfn>escaped</dfn> inside a string. Here is a table of common escape sequences:",
"<table class=\"table table-striped\"><thead><tr><th>Code</th><th>Output</th></tr></thead><tbody><tr><td>\\'</td><td>single quote</td></tr><tr><td>\\\"</td><td>double quote</td></tr><tr><td>\\\\</td><td>backslash</td></tr><tr><td>\\n</td><td>new line</td></tr><tr><td>\\r</td><td>carriage return</td></tr><tr><td>\\t</td><td>tab</td></tr><tr><td>\\b</td><td>backspace</td></tr><tr><td>\\f</td><td>form feed</td></tr></tbody></table>",
"<table class=\"table table-striped\"><thead><tr><th>Code</th><th>Output</th></tr></thead><tbody><tr><td><code>\\'</code></td><td>single quote</td></tr><tr><td><code>\\\"</code></td><td>double quote</td></tr><tr><td><code>\\\\</code></td><td>backslash</td></tr><tr><td><code>\\n</code></td><td>new line</td></tr><tr><td><code>\\r</code></td><td>carriage return</td></tr><tr><td><code>\\t</code></td><td>tab</td></tr><tr><td><code>\\b</code></td><td>backspace</td></tr><tr><td><code>\\f</code></td><td>form feed</td></tr></tbody></table>",
"<em>Note that the backslash itself must be escaped in order to display as a backslash.</em>",
"<h4>Instructions</h4>",
"Encode the following sequence, separated by spaces:<br><code>backslash tab tab carriage-return new-line</code> and assign it to <code>myStr</code>"
"Assign the following two lines of text into the single variable <code>myStr</code> using escape sequences.",
"<blockquote>Here is a backslash: \\.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Here is a new line with two tabs.</blockquote>",
"You will need to use escape sequences to insert special characters correctly. You will also need to follow the spacing as it looks above with no additional spaces between each escape sequence.",
"Here is the text with the escape sequences written out.",
"<q>Here is a backslash: <code>backslash</code>.<code>newline</code> <code>tab</code> <code>tab</code> Here is a new line with two tabs.</q>"
],
"releasedOn": "January 1, 2016",
"challengeSeed": [
@ -1054,10 +1058,14 @@
"else{return null;}})();"
],
"solutions": [
"var myStr = \"\\\\ \\t \\t \\r \\n\";"
"var myStr = \"Here is a backslash: \\\\.\\n\\t\\tHere is a new line with two tabs.\";"
],
"tests": [
"assert(myStr === \"\\\\ \\t \\t \\r \\n\", 'message: <code>myStr</code> should have the escape sequences for <code>backslash tab tab carriage-return new-line</code> separated by spaces');"
"assert(myStr === \"Here is a backslash: \\\\.\\n\\t\\tHere is a new line with two tabs.\", 'message: <code>myStr</code> should have encoded text with the proper escape sequences and spacing.');",
"assert(myStr.match(/\\t/g).length == 2, 'message: <code>myStr</code> should have two tab characters <code>\\t</code>');",
"assert(myStr.match(/\\n/g).length == 1, 'message: <code>myStr</code> should have one newline character <code>\\n</code>');",
"assert(myStr.match(/\\\\/g).length == 1, 'message: <code>myStr</code> should have a correctly escaped backslash character <code>\\\\</code>');",
"assert(myStr === \"Here is a backslash: \\\\.\\n\\t\\tHere is a new line with two tabs.\", 'message: <code>myStr</code> should not have any spaces in between consecutive escape sequences.');"
],
"type": "waypoint",
"challengeType": 1,