* chore(learn): audit basic algorithm scripting * chore(learn): audit basic data structures * chore(learn): audit basic javascript * chore(learn): audit debugging * chore(learn): audit es6 * chore(learn): audit functional programming * chore(learn): audit intermidate algorithms * chore(learn): audit js projects * chore(learn): audit object oriented programming * chore(learn): audit regex * fix(learn): remove stray . * fix(learn): string to code * fix(learn): missed some * fix(learn): clarify strings Based on Randy's feedback, clarifies string instances where quotes were removed in favour of back ticks. * fix: apply suggestions - thanks Randy! :) Co-authored-by: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> * fix: non-suggestion comments * chore(learn): remove comments from codes Removes the comments from the description and instruction code blocks to ensure that all relevant information is translatable. * fix: Apply suggestions from code review Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> * fix: revert crowdin fix * Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-algorithm-scripting/mutations.md Co-authored-by: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> * fix: Apply suggestions from code review Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> * Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/use-destructuring-assignment-to-assign-variables-from-arrays.md Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> * fix: Apply suggestions from code review Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> * chore: change voice * fix: Christopher Nolan * fix: expressions would evaluate * fix: will -> would * Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/add-methods-after-inheritance.md Co-authored-by: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> * fix: to work to push * Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-with-javascript-for-loops.md Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> * Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/add-methods-after-inheritance.md Co-authored-by: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> Co-authored-by: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
64 lines
1.9 KiB
Markdown
64 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
|
|
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.'";
|
|
const uhOhGroucho = 'I've had a perfectly wonderful evening, but this wasn't it.';
|
|
```
|
|
|
|
The first two are correct, but the third is incorrect.
|
|
|
|
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
|
|
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);
|
|
```
|