2.7 KiB
2.7 KiB
id, title, challengeType, videoUrl, forumTopicId, localeTitle
id | title | challengeType | videoUrl | forumTopicId | localeTitle |
---|---|---|---|---|---|
56533eb9ac21ba0edf2244b5 | Escaping Literal Quotes in Strings | 1 | https://scrimba.com/c/c2QvgSr | 17568 | Исключение буквенных котировок в строках |
Description
"
или '
внутри вашей строки? В JavaScript вы можете избежать цитаты, рассматривая ее как конец строки, помещая обратную косую черту ( \
) перед цитатой. var sampleStr = "Alan said, \"Peter is learning JavaScript\".";
Это сигнализирует JavaScript, что следующая цитата не является концом строки, но должна появляться внутри строки. Поэтому, если вы должны были напечатать это на консоли, вы бы получили: Alan said, "Peter is learning JavaScript".
Instructions
myStr
чтобы, если вы должны были ее распечатать на консоль, вы увидите: « I am a "double quoted" string inside "double quotes".
Tests
tests:
- text: You should use two double quotes (<code>"</code>) and four escaped double quotes (<code>\"</code>).
testString: assert(code.match(/\\"/g).length === 4 && code.match(/[^\\]"/g).length === 2);
- text: 'Variable myStr should contain the string: <code>I am a "double quoted" string inside "double quotes".</code>'
testString: assert(myStr === "I am a \"double quoted\" string inside \"double quotes\".");
Challenge Seed
var myStr = ""; // Change this line
After Tests
(function(){
if(typeof myStr === 'string') {
console.log("myStr = \"" + myStr + "\"");
} else {
console.log("myStr is undefined");
}
})();
Solution
var myStr = "I am a \"double quoted\" string inside \"double quotes\".";