Some newbie troubles

so this Is my code so far and I’m having trouble because it says that I can only use two double quotes and I don’t see how that’s possible to do. Thanks!

My code so far


var myStr = 'I am a \"double quoted\" string inside \"double quotes\".'; // Change this line

Challenge: Escaping Literal Quotes in Strings

Link to the challenge:

Hey! You’ve done all the hard work already. Instead of wrapping it in single quotes '' you should change these to double quotes "" and your code will pass. :+1:

1 Like

Hi, StDucky! As jonathankerr said, you’ll be good to go if you wrap the whole string in double quotes.

What you’ve initially written, a string wrapped in single quotes with double quoted segments within, would work in a normal coding environment, but the purpose of this exercise is how to get quotation marks to show up properly when you use the same type of quotation mark to wrap the whole string.

For example, you might want to write something like this,:

var singleQuoteStr = ‘I am a ‘single quoted’ string.’;
var doubleQuoteStr = “I am a “double quoted” string.”;

Note that the above would not work, because when Javascript sees a second occurrence of the same type of quotation mark you use to wrap the string, it thinks the string is ending, leading to errors. Javascript would think singleQuoteStr had a value of I am a followed by some text single quoted’ string’ that it doesn’t know what to do with.

So, I would need to either do what you did, which is to wrap the whole thing in a different type of quotation mark than what I’m using for the quoted segment within (which would then not require escaping with backslashes), or I could use whatever type of quotation mark I wanted for both wrapping the whole string and for quoted segments with the help of escaping with backslashes, as in the exercise.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.