2018-09-30 22:01:58 +00:00
---
id: 587d7b84367417b2b2512b37
title: Catch Mixed Usage of Single and Double Quotes
challengeType: 1
2019-08-05 16:17:33 +00:00
forumTopicId: 301188
2021-01-13 02:31:00 +00:00
dashedName: catch-mixed-usage-of-single-and-double-quotes
2018-09-30 22:01:58 +00:00
---
2020-11-27 18:02:05 +00:00
# --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.
2018-09-30 22:01:58 +00:00
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.
2020-11-27 18:02:05 +00:00
2018-09-30 22:01:58 +00:00
Here are some examples of mixing quotes:
2019-05-17 13:20:30 +00:00
```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.';
```
2021-03-03 00:12:12 +00:00
The first two are correct, but the third is incorrect.
2021-03-09 16:13:27 +00:00
Of course, it is okay to use only one style of quotes. You can escape the quotes inside the string by using the backslash (`\`) escape character:
2019-05-17 13:20:30 +00:00
```js
const allSameQuotes = 'I\'ve had a perfectly wonderful evening, but this wasn\'t it.';
```
2020-11-27 18:02:05 +00:00
# --instructions--
2018-09-30 22:01:58 +00:00
2020-11-27 18:02:05 +00:00
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.
2018-09-30 22:01:58 +00:00
2020-11-27 18:02:05 +00:00
# --hints--
2018-09-30 22:01:58 +00:00
2021-03-03 00:12:12 +00:00
Your code should fix the quotes around the `href` value `#Home` by either changing or escaping them.
2018-09-30 22:01:58 +00:00
2020-11-27 18:02:05 +00:00
```js
assert(code.match(/< a href = \s*?('| \\")#Home \1\s*? > /g));
2018-09-30 22:01:58 +00:00
```
2020-11-27 18:02:05 +00:00
Your code should keep the double quotes around the entire string.
```js
assert(code.match(/"< p > .*?< \/p > ";/g));
```
2018-09-30 22:01:58 +00:00
2020-11-27 18:02:05 +00:00
# --seed--
2018-09-30 22:01:58 +00:00
2020-11-27 18:02:05 +00:00
## --seed-contents--
2018-09-30 22:01:58 +00:00
```js
let innerHtml = "< p > Click here to < a href = "#Home" > return home< / a > < / p > ";
console.log(innerHtml);
```
2020-11-27 18:02:05 +00:00
# --solutions--
2018-09-30 22:01:58 +00:00
```js
2019-04-18 18:44:20 +00:00
let innerHtml = "< p > Click here to < a href = \"#Home \"> return home </ a ></ p > ";
console.log(innerHtml);
2018-09-30 22:01:58 +00:00
```