* fix(learn): address escaped backticks Addresses the instances of escaped backticks - where a backtick is preceded by a backslash. In most cases, this was left over from the old parser. In some cases, a backtick was intended to be wrapped in code tags and has been adjusted accordingly. This issue came to light due to a bug in the translation flow on Crowdin. Signed-off-by: nhcarrigan <nhcarrigan@gmail.com> * fix: EVEN MORE :( :( :( Signed-off-by: nhcarrigan <nhcarrigan@gmail.com> * fix: backslash nightmares Signed-off-by: nhcarrigan <nhcarrigan@gmail.com> * fix: When you wish upon a ******* Signed-off-by: nhcarrigan <nhcarrigan@gmail.com> * fix(curriculum): md error introduced by formatter * fix(curriculum): remove extra `s * fix: restore quote symbol Signed-off-by: nhcarrigan <nhcarrigan@gmail.com> * fix: Typo Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: apply review changes Applying review feedback from call with @RandellDawson. Signed-off-by: nhcarrigan <nhcarrigan@gmail.com> * fix: markdown does weird stuff sometimes Can't stick backticks together - use code. Signed-off-by: nhcarrigan <nhcarrigan@gmail.com> Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
65 lines
1.9 KiB
Markdown
65 lines
1.9 KiB
Markdown
---
|
|
id: 587d7b84367417b2b2512b37
|
|
title: Catch Mixed Usage of Single and Double Quotes
|
|
challengeType: 1
|
|
forumTopicId: 301188
|
|
dashedName: catch-mixed-usage-of-single-and-double-quotes
|
|
---
|
|
|
|
# --description--
|
|
|
|
JavaScript allows the use of both single (`'`) and double (`"`) quotes to declare a string. Deciding which one to use generally comes down to personal preference, with some exceptions.
|
|
|
|
Having two choices is great when a string has contractions or another piece of text that's in quotes. Just be careful that you don't close the string too early, which causes a syntax error.
|
|
|
|
Here are some examples of mixing quotes:
|
|
|
|
```js
|
|
// 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.';
|
|
```
|
|
|
|
Of course, it is okay to use only one style of quotes. You can escape the quotes inside the string by using the backslash (<code>\\</code>) escape character:
|
|
|
|
```js
|
|
// Correct use of same quotes:
|
|
const allSameQuotes = 'I\'ve had a perfectly wonderful evening, but this wasn\'t it.';
|
|
```
|
|
|
|
# --instructions--
|
|
|
|
Fix the string so it either uses different quotes for the `href` value, or escape the existing ones. Keep the double quote marks around the entire string.
|
|
|
|
# --hints--
|
|
|
|
Your code should fix the quotes around the `href` value "#Home" by either changing or escaping them.
|
|
|
|
```js
|
|
assert(code.match(/<a href=\s*?('|\\")#Home\1\s*?>/g));
|
|
```
|
|
|
|
Your code should keep the double quotes around the entire string.
|
|
|
|
```js
|
|
assert(code.match(/"<p>.*?<\/p>";/g));
|
|
```
|
|
|
|
# --seed--
|
|
|
|
## --seed-contents--
|
|
|
|
```js
|
|
let innerHtml = "<p>Click here to <a href="#Home">return home</a></p>";
|
|
console.log(innerHtml);
|
|
```
|
|
|
|
# --solutions--
|
|
|
|
```js
|
|
let innerHtml = "<p>Click here to <a href=\"#Home\">return home</a></p>";
|
|
console.log(innerHtml);
|
|
```
|