freeCodeCamp Challenge Guide: Escape Sequences in Strings

Hey there!
also stuck. got 3/4 with the first box still red. It says myStr should have encoded text with the proper escape sequences and no spacing. ???
Also I’m confused why all the suggested answers seem to be losing slashes along the way.

There is \n for Newline
\\ for backslash
and \r for Return

When combined shouldn’t it say

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

and not

var myStr = “FirstLine\n\SecondLine\rThirdLine”;
as many have suggested?

UPDATE: this is the exact passing code

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

2 Likes

People seem to have differing answers for this one. I struggled with it for awhile.
Here is what I got to pass the lesson.

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

1 Like

both the string r same only difference is the word Thirdline in first string havng ‘l’ and in 2nd it is ‘L:grinning:’

If you stuck try this:

var myStr; // Change this line
myStr = ‘FirstLine\n\SecondLine\\rThirdLine’;

1 Like

Hy,

This is what I also got,and it ran well.

var myStr=‘FirstLine\n\SecondLine\\rThirdLine’;

Look at the symbols and their names, then follow the instructions:

“FirstLine newline backslash SecondLine backslash carriage-return ThirdLine”

The answer is surprisingly easy.

’ single quote
" double quote
\ backslash
\n newline
\r carriage return
\t tab
\b backspace
\f form feed

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

Your line of code works except that you forgot the ;

1 Like

i’m noticing alot of “help” on here and alot of missing slashes.

var myStr = “FirstLine\n\\SecondLine\\\rThirdLine”;
The folks trying to help are forgetting that coding rules apply here on the forum as well so you keep seeing this: var myStr = “FirstLine\n\SecondLine\\rThirdLine”;

Breaking it down:

var myStr =

“FirstLine - Notice all of the words have capitalized first letters just to screw with you.
/n - New line. No spaces.
\\SecondLine\\ - On the left of the full string above there’s only two backslashes because in order for one to show up you need two. On the right the extra one (making three total) is for the carriage-return command.
\rThirdLine”; - Don’t forget your end quote and semi-colon!

I hope that clears alot of this up and god help me if I missed something.

6 Likes

me2.

THANKS for HELP! :slight_smile:

1 Like