freeCodeCamp Challenge Guide: Escape Sequences in Strings

i can’t pass this exercise …lol … i try anythings ^^

2 Likes

Try with this: var myStr = “FirstLine\n\SecondLine\\rThirdLine”;

1 Like

This is because:

  1. new line is: \n

  2. Backslash: \ content here \ - there will be two backslash’s for each side

  3. carriage-return: \r

Put it together(I’ll put spaces inbetween to make it easier to read):

“FirstLine \n \SecondLine\ \r ThirdLine”

2 Likes

Try this solution it will work for you:
var myStr = “FirstLine\n\SecondLine\\rThirdLine”;

Why is this line not working var myStr= ‘FirstLine\n\SecondLine\rThirdLine’;

var myStr=“FirstLine\n\SecondLine\\rThirdLine”;

Oh my goodness! Spelling and attention to detail counts. I couldn’t figure out why it wasn’t working until I saw your post and reviewed my code. I went nuts for a minute.

1 Like

hi, guys, try this code for this challenge, it will work.
var myStr=‘FirstLine\n\SecondLine\\rThirdLine’; // Change this line

Hi,
This has worked for me

var myStr = "FirstLine\n\\SecondLine\\\rThirdLine";
8 Likes

Here’s the correct solution guys

var myStr = “FirstLine\n\SecondLine\\rThirdLine”; // Change this line

Try this var myStr =“FirstLine\n\Second\\rThirdLine”;

Ruben has the correct answer. I don’t know how these other answers pass the test. I quote the note in the lesson/instructions.

Note that the backslash itself must be escaped in order to display as a backslash.

var myStr = “FirstLine\n\SecondLine\\rThirdLine”

1 Like

Hello guys, this whole thing is just, look carefully. I got it now. Here’s my answer:
var myStr = “FirstLine\n\SecondLine\\rThirdLine”;
All got ticked. Lol. It’s a double slash (\) not a single slash () for backslash.

Look at the escape sequences in the table:

\\ This is what denotes a backslash.

They said:

"FirstLine newline backslash (which is supposed to be \

Yes he has the correct answer

try this it worked;
var myStr =“FirstLine\n\SecondLine\\rThirdLine”; //change this line

ive jus put the code from ChonyWang and jus added

after the \n this \ and after the \ added this \r.
hope it helps good luck

var myStr=‘FirstLine\n\SecondLine\\rThirdLine’; try this its working.

escaping of \ will be required.
var myStr = “FirstLine\n\SecondLine\\rThirdLine”;

Hey guys!

I’ve got 3/4 with this
var myStr =‘FirstLine\n\SecondLine\ThirdLine\r’ ; // Change this line

This is my error; myStr should have encoded text with the proper escape sequences and no spacing.

i dont quite understand what’s gone wrong though. Help? x

Hi there,
In the first line, you word “Thirdline”, the letter l is lowercase.
In the second line, it is uppercase as it should be.

That’s why the second one ticks all boxes

1 Like