2.1 KiB
2.1 KiB
id, title, challengeType, forumTopicId, localeTitle
id | title | challengeType | forumTopicId | localeTitle |
---|---|---|---|---|
587d7b84367417b2b2512b37 | Catch Mixed Usage of Single and Double Quotes | 1 | 301188 | 捕捉单引号和双引号的混合用法 |
Description
// These are correct:
const grouchoContraction = "I've had a perfectly wonderful evening, but this wasn't it.";
const quoteInString = "Groucho Marx once said 'Quote me as saying I was mis-quoted.'";
// This is incorrect:
const uhOhGroucho = 'I've had a perfectly wonderful evening, but this wasn't it.';
当然,只使用一种引号是可以的。你可以使用反斜杠 (\
) 转义字符来转义字符串中的引号:
// 一种引号的正确使用方式
const allSameQuotes = 'I\'ve had a perfectly wonderful evening, but this wasn\'t it.';
Instructions
href
属性的值使用不同的引号,或者转义现有的引号。注意,整个字符串外面的双引号要保留。
Tests
tests:
- text: "你应通过更改或转义来修复<code>href</code>的值 '#Home' 周围的引号。"
testString: assert(code.match(/<a href=\s*?('|\\")#Home\1\s*?>/g));
- text: 你应该在整个字符串外围保留双引号。
testString: assert(code.match(/"<p>.*?<\/p>";/g));
Challenge Seed
let innerHtml = "<p>Click here to <a href="#Home">return home</a></p>";
console.log(innerHtml);
Solution
let innerHtml = "<p>Click here to <a href=\"#Home\">return home</a></p>";
console.log(innerHtml);