Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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,775 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!