freeCodeCamp Challenge Guide: Escaping Literal Quotes in Strings

Escaping Literal Quotes in Strings


Hints

Hint 1

  • When you need to use a special character such as " inside a string you need to escape it using \.
  • If you use double quotes " for the string, single quotes ' in the string do not need to be escaped.
  • If you use single quotes ' for the string, double quotes " in the string do not need to be escaped.

Solutions

Solution 1 (Click to Show/Hide)
var myStr = 'I am a "double quoted" string inside "double quotes".';
var otherStr = "I am a 'single quoted' string inside 'single quotes'.";
var noEscapeSingle = "There is no need to 'escape' the single quotes.";
var noEscapeDouble = 'There is no need to "escape" the double quotes.';
5 Likes

var myStr = “I am a “doubled quoted” string inside “double quotes”.”; // Change this line

what’s wrong with this ?

what is wrong with this:

var myStr = "I am a “double quoted” string inside “double quotes”. ";

2 Likes

you put a space in front of the period, if you erase it, you will have the answer. Nice Job, Though!

3 Likes

I have the same issue. Resolved it yet?

It’s resolved, I misspelled quoted

2 Likes

Even I did the same too xD

for anyone that didn’t get the correct answer. here ya go

22 Likes

Hey so I read over the comments but I’m still not understanding exactly what I did wrong. I have “I am a “double quoted” string inside “double quotes”.”;

2 Likes

Make sure you have the full stops and spaces where they are supposed to be :slight_smile: also include the backslashes like the example above.

1 Like

i got the miss its the capitalize . .
right code >> var myStr = “I am a “double quoted” string inside “double quotes”.”;

wrong code >> var myStr = “i am a “double quoted” string inside “double quotes”.”;

1 Like

Thank you ! I think it was a glitch because it says I completed that assignment now.

1 Like

The following worked for me -

var myStr = “I am a “double quoted” string inside “double quotes”.”;

its not doubled its double u change that one …it will work

Correct ans: var myStr=“I am a “double quoted” string inside “double quotes”.”;

it still doesn’t work

1 Like

A post was split to a new topic: Having trouble passing Escaping Literal Quotes in Strings

They mean just as like in the example

var sampleStr = "Alan said, \"Peter is learning JavaScript\".";

I am a /"double quoted/" string inside "double quotes".
the / comes before " and then after the "

Correct

ans: var myStr=I am a \"double quoted"\ string inside \"double quotes\".

before the " and then after the " we place
so " "\