60 lines
2.9 KiB
Markdown
60 lines
2.9 KiB
Markdown
---
|
||
id: 56533eb9ac21ba0edf2244b5
|
||
title: Escaping Literal Quotes in Strings
|
||
challengeType: 1
|
||
videoUrl: ''
|
||
localeTitle: Исключение буквенных котировок в строках
|
||
---
|
||
|
||
## Description
|
||
<section id="description"> Когда вы определяете строку, вы должны начинать и заканчивать одиночную или двойную кавычку. Что происходит, когда вам нужна буквальная цитата: <code>"</code> или <code>'</code> внутри вашей строки? В JavaScript вы можете <dfn>избежать</dfn> цитаты, рассматривая ее как конец строки, помещая <dfn>обратную косую черту</dfn> ( <code>\</code> ) перед цитатой. <code>var sampleStr = "Alan said, \"Peter is learning JavaScript\".";</code> Это сигнализирует JavaScript, что следующая цитата не является концом строки, но должна появляться внутри строки. Поэтому, если вы должны были напечатать это на консоли, вы бы получили: <code>Alan said, "Peter is learning JavaScript".</code> </section>
|
||
|
||
## Instructions
|
||
<section id="instructions"> Используйте <dfn>обратную косую черту,</dfn> чтобы назначить строку переменной <code>myStr</code> чтобы, если вы должны были ее распечатать на консоль, вы увидите: « <code>I am a "double quoted" string inside "double quotes".</code> </section>
|
||
|
||
## Tests
|
||
<section id='tests'>
|
||
|
||
```yml
|
||
tests:
|
||
- text: Вы должны использовать две двойные кавычки ( <code>"</code> ) и четыре сэкономленные двойные кавычки ( <code>\"</code> ).
|
||
testString: 'assert(code.match(/\\"/g).length === 4 && code.match(/[^\\]"/g).length === 2, "You should use two double quotes (<code>"</code>) and four escaped double quotes (<code>\"</code>).");'
|
||
- text: 'Переменная myStr должна содержать строку: <code>I am a "double quoted" string inside "double quotes".</code>'
|
||
testString: 'assert(myStr === "I am a \"double quoted\" string inside \"double quotes\".", "Variable myStr should contain the string: <code>I am a "double quoted" string inside "double quotes".</code>");'
|
||
|
||
```
|
||
|
||
</section>
|
||
|
||
## Challenge Seed
|
||
<section id='challengeSeed'>
|
||
|
||
<div id='js-seed'>
|
||
|
||
```js
|
||
var myStr = ""; // Change this line
|
||
|
||
```
|
||
|
||
</div>
|
||
|
||
|
||
### After Test
|
||
<div id='js-teardown'>
|
||
|
||
```js
|
||
console.info('after the test');
|
||
```
|
||
|
||
</div>
|
||
|
||
</section>
|
||
|
||
## Solution
|
||
<section id='solution'>
|
||
|
||
```js
|
||
// solution required
|
||
```
|
||
</section>
|