Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialMike McKnight
6,717 PointsQuestion about quotes.
A lot of people are asking which is better to use single or double and the answer seems to be preference unless your string contains one, then use the other. But what if the sentence you were trying to make appear on a web page was:
Susan said "She's going to be in trouble."
Since it has both a single and a double what would you do there.
2 Answers
Steven Parker
231,236 PointsFor this, you could use the escape character (\
) to indicate which marks are content.
Using your example:
document.write("Susan said \"She's going to be in trouble.\"");
As an alternative you could enclose everything in accents (back-ticks). They are typically used to create template strings but can be a third type of string identifier:
document.write(`Susan said "She's going to be in trouble."`);
Antonio Ascue Avalos
3,023 PointsGreat question and answer