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 JavaScript Foundations Strings Escape Characters

Mark Lovett
Mark Lovett
15,853 Points

This one appears to be broken

It doesnt like this code:

var escapedNewLine = 'This is a\nbrand new line'; console.log(escapedNewLine);

3 Answers

Mark Lovett
Mark Lovett
15,853 Points

This is what they want: \n

Ok. Thanks much!

Hi Mark,

You have to take the instructions literally.

For task 1, it says "Set the 'escapedNewLine' variable to the string of a new line character."

All that should be in your string is the new line character. Not all the extra text that you have.

Also, the conole.log statement isn't requested in the instructions. Not sure if it will pass with them in.

It will also pass with single quotes.

James Barnett
James Barnett
39,199 Points

> All that should be in your string is the new line character. Not all the extra text that you have.

This is a tough call. I'm tempted to say this should be reported as an overly specific code correctness check.

I don't know.

I would think that the instructions would have to be something like "Set the 'escapedNewLine' variable to a string with a new line character in it." in order to indicate that it would be ok to add extra characters of your choosing if you wanted to.

I suppose you could tag whose in charge.

James Barnett
James Barnett
39,199 Points

Jason Anello -

I suppose you've got a point there.

James Barnett
James Barnett
39,199 Points

> Also, the console.log statement isn't requested in the instructions. Not sure if it will pass with them in.

It will.

It's probably because your'e using single-quotes. Typically, the only escape sequences that work inside single-quotes are other single-quotes \' and backslashes \\. Try it with double-quotes instead.

var escapedNewLine = "This is a\nbrand new line";
console.log(escapedNewLine);