.github
api-server
client
config
curriculum
__fixtures__
challenges
_meta
chinese
english
01-responsive-web-design
02-javascript-algorithms-and-data-structures
basic-algorithm-scripting
basic-data-structures
basic-javascript
access-array-data-with-indexes.md
access-multi-dimensional-arrays-with-indexes.md
accessing-nested-arrays.md
accessing-nested-objects.md
accessing-object-properties-with-bracket-notation.md
accessing-object-properties-with-dot-notation.md
accessing-object-properties-with-variables.md
add-new-properties-to-a-javascript-object.md
add-two-numbers-with-javascript.md
adding-a-default-option-in-switch-statements.md
appending-variables-to-strings.md
assigning-the-value-of-one-variable-to-another.md
assignment-with-a-returned-value.md
build-javascript-objects.md
chaining-if-else-statements.md
comment-your-javascript-code.md
comparison-with-the-equality-operator.md
comparison-with-the-greater-than-operator.md
comparison-with-the-greater-than-or-equal-to-operator.md
comparison-with-the-inequality-operator.md
comparison-with-the-less-than-operator.md
comparison-with-the-less-than-or-equal-to-operator.md
comparison-with-the-strict-equality-operator.md
comparison-with-the-strict-inequality-operator.md
comparisons-with-the-logical-and-operator.md
comparisons-with-the-logical-or-operator.md
compound-assignment-with-augmented-addition.md
compound-assignment-with-augmented-division.md
compound-assignment-with-augmented-multiplication.md
compound-assignment-with-augmented-subtraction.md
concatenating-strings-with-plus-operator.md
concatenating-strings-with-the-plus-equals-operator.md
constructing-strings-with-variables.md
count-backwards-with-a-for-loop.md
counting-cards.md
create-decimal-numbers-with-javascript.md
declare-javascript-variables.md
declare-string-variables.md
decrement-a-number-with-javascript.md
delete-properties-from-a-javascript-object.md
divide-one-decimal-by-another-with-javascript.md
divide-one-number-by-another-with-javascript.md
escape-sequences-in-strings.md
escaping-literal-quotes-in-strings.md
find-the-length-of-a-string.md
finding-a-remainder-in-javascript.md
generate-random-fractions-with-javascript.md
generate-random-whole-numbers-with-javascript.md
generate-random-whole-numbers-within-a-range.md
global-scope-and-functions.md
global-vs.-local-scope-in-functions.md
golf-code.md
increment-a-number-with-javascript.md
initializing-variables-with-the-assignment-operator.md
introducing-else-if-statements.md
introducing-else-statements.md
iterate-odd-numbers-with-a-for-loop.md
iterate-through-an-array-with-a-for-loop.md
iterate-with-javascript-do...while-loops.md
iterate-with-javascript-for-loops.md
iterate-with-javascript-while-loops.md
local-scope-and-functions.md
logical-order-in-if-else-statements.md
manipulate-arrays-with-pop.md
manipulate-arrays-with-push.md
manipulate-arrays-with-shift.md
manipulate-arrays-with-unshift.md
manipulating-complex-objects.md
modify-array-data-with-indexes.md
multiple-identical-options-in-switch-statements.md
multiply-two-decimals-with-javascript.md
multiply-two-numbers-with-javascript.md
nest-one-array-within-another-array.md
nesting-for-loops.md
passing-values-to-functions-with-arguments.md
practice-comparing-different-values.md
profile-lookup.md
quoting-strings-with-single-quotes.md
record-collection.md
replace-loops-using-recursion.md
replacing-if-else-chains-with-switch.md
return-a-value-from-a-function-with-return.md
return-early-pattern-for-functions.md
returning-boolean-values-from-functions.md
selecting-from-many-options-with-switch-statements.md
shopping-list.md
stand-in-line.md
store-multiple-values-in-one-variable-using-javascript-arrays.md
storing-values-with-the-assignment-operator.md
subtract-one-number-from-another-with-javascript.md
testing-objects-for-properties.md
understand-string-immutability.md
understanding-boolean-values.md
understanding-case-sensitivity-in-variables.md
understanding-undefined-value-returned-from-a-function.md
understanding-uninitialized-variables.md
updating-object-properties.md
use-bracket-notation-to-find-the-first-character-in-a-string.md
use-bracket-notation-to-find-the-last-character-in-a-string.md
use-bracket-notation-to-find-the-nth-character-in-a-string.md
use-bracket-notation-to-find-the-nth-to-last-character-in-a-string.md
use-conditional-logic-with-if-statements.md
use-multiple-conditional-ternary-operators.md
use-recursion-to-create-a-countdown.md
use-recursion-to-create-a-range-of-numbers.md
use-the-conditional-ternary-operator.md
use-the-parseint-function-with-a-radix.md
use-the-parseint-function.md
using-objects-for-lookups.md
word-blanks.md
write-reusable-javascript-with-functions.md
basic-javascript-rpg-game
debugging
es6
functional-programming
functional-programming-spreadsheet
intermediate-algorithm-scripting
intermediate-javascript-calorie-counter
javascript-algorithms-and-data-structures-projects
object-oriented-programming
regular-expressions
03-front-end-libraries
04-data-visualization
05-apis-and-microservices
06-quality-assurance
07-scientific-computing-with-python
08-data-analysis-with-python
09-information-security
10-coding-interview-prep
11-machine-learning-with-python
12-certificates
schema
test
.babelrc
LICENSE.md
comment-dictionary.js
create-challenge-bundle.js
getChallenges.acceptance.test.js
getChallenges.js
getChallenges.test.js
gulpfile.js
lib.js
package-entry.js
package-lock.json
package.json
utils.js
cypress
docs
tools
utils
.editorconfig
.eslintignore
.eslintrc.json
.gitattributes
.gitignore
.gitpod.yml
.node-inspectorrc
.npmrc
.prettierignore
.prettierrc
.snyk
.vcmrc
CODE_OF_CONDUCT.md
CONTRIBUTING.md
HoF.md
LICENSE.md
README.md
SECURITY.md
change_volumes_owner.sh
crowdin.yml
cypress-install.js
cypress.json
jest.config.js
lerna.json
lighthouserc.js
package-lock.json
package.json
sample.env
3.3 KiB
3.3 KiB
id, title, challengeType, videoUrl, forumTopicId
id | title | challengeType | videoUrl | forumTopicId |
---|---|---|---|---|
56533eb9ac21ba0edf2244b6 | Escape Sequences in Strings | 1 | https://scrimba.com/c/cvmqRh6 | 17567 |
Description
- To allow you to use characters you may not otherwise be able to type out, such as a carriage return.
- To allow you to represent multiple quotes in a string without JavaScript misinterpreting what you mean.
Code | Output |
---|---|
\' | single quote |
\" | double quote |
\\ | backslash |
\n | newline |
\r | carriage return |
\t | tab |
\b | word boundary |
\f | form feed |
Instructions
myStr
using escape sequences.
FirstLineYou 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 spaces between escape sequences or words. Here is the text with the escape sequences written out.
\SecondLine
ThirdLine
FirstLinenewline
tab
backslash
SecondLinenewline
ThirdLine
Tests
tests:
- text: <code>myStr</code> should not contain any spaces
testString: assert(!/ /.test(myStr));
- text: <code>myStr</code> should contain the strings <code>FirstLine</code>, <code>SecondLine</code> and <code>ThirdLine</code> (remember case sensitivity)
testString: assert(/FirstLine/.test(myStr) && /SecondLine/.test(myStr) && /ThirdLine/.test(myStr));
- text: <code>FirstLine</code> should be followed by the newline character <code>\n</code>
testString: assert(/FirstLine\n/.test(myStr));
- text: <code>myStr</code> should contain a tab character <code>\t</code> which follows a newline character
testString: assert(/\n\t/.test(myStr));
- text: <code>SecondLine</code> should be preceded by the backslash character <code>\</code>
testString: assert(/\\SecondLine/.test(myStr));
- text: There should be a newline character between <code>SecondLine</code> and <code>ThirdLine</code>
testString: assert(/SecondLine\nThirdLine/.test(myStr));
- text: <code>myStr</code> should only contain characters shown in the instructions
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";