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 trial

JavaScript The Solution

Em Ruzzy
Em Ruzzy
2,165 Points

My solution worked without escape characters, are they mandatory?

My solution worked without the escape characters in alert().

Do we need to add the escape characters in this problem? I'm not sure why mine worked without them:

var firstName = prompt('Please type your first name.'); var lastName = prompt('Please type your last name.'); var fullName = firstName.toUpperCase() + ' ' + lastName.toUpperCase(); var characterCount = fullName.length; alert("This string " + fullName + " is " + characterCount + " characters long.");

2 Answers

Your code does work without the escape characters, but it will not put quotes around the name. For example, if I enter my name, your output is: this string MIKE FRANCOIS is 12 characters long. With the escape characters added the output would be: this string "MIKE FRANCOIS" is 12 characters long. The escape characters will treat the quotes as a character. hope that helps.

Em Ruzzy
Em Ruzzy
2,165 Points

Absolutely right - thanks Mike!

Tyler B
Tyler B
5,787 Points

The Solution shown has the full name variable surrounded by quotes. Your version does not have those so you didn't need to escape any of the other characters. To answer your question escape characters will always be mandatory In the case where you are using characters that are reserved for special uses i.e. ""

Em Ruzzy
Em Ruzzy
2,165 Points

Thanks for your help Tyler!