freeCodeCamp Challenge Guide: Escape Sequences in Strings

Escape Sequences in Strings


Solutions

Solution 1 (Click to Show/Hide)
var myStr = "FirstLine\n\t\\SecondLine\nThirdLine";
73 Likes

Hello!

I am stuck
var myStr = ‘FirstLine\n \SecondLine\ \r ThirsLine’; // Change this line
var myStr = ‘FirstLine\n \SecondLine\ \rThirsLine’; // Change this line
var myStr = ‘FirstLine\n \SecondLine\ \r ThirsLine’; // Change this line
var myStr = ‘FirstLine \n \SecondLine\ \rThirsLine’; // Change this line

What I can pass: myStr should have encoded text with the proper escape sequences and no spacing.

I tried this: var myStr = ‘FirstLine\n\SecondLine\\rThirsLine’; // Change this line

Also, evidently, I dont understand this sentence: Note that the backslash itself must be escaped in order to display as a backslash. )))

Please help! )))

I also also stated reading the description of “Desing patterns” by Gang of Four, and programming seems not what it seemed. There is a reason why they pay good money! Because I dont understand what is inside Behavorial, Structural and Creational.

with best regards

happyMutant2

10 Likes

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

7 Likes

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

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

4 Likes

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

1 Like

var myStr=“FirstLine\n\SecondLine\\rThirdLine”; // Change this line tip the ‘\r’ cannot use it in the end

1 Like

These lesson clearly says that

FirstLine newline, backslash SecondLine backslash , carriage-return ThirdLine

It clearly show’s that we must first write:-
var myStr = "FirstLine\n\\SecondLine\\\rThirdLine"

After writing FirstLine \n which mean new line as given above followed by \SecondLine\ in order to escape from \ we use \ before and after of \SecondLine\ thus it become \SecondLine\and lastly carriage-return which is\r` followed by ThirdLine.

66 Likes
 var myStr = "FirstLine\n\\SecondLine\\\rThirdline";//doesn't tick the 1st box
 var myStr = "FirstLine\n\\SecondLine\\\rThirdLine";//ticks all boxes

Can anyone explain what’s the difference between the 1st and 2nd lines?

4 Likes

You mean
var myStr = “FirstLine\n\SecondLine\rThirdline”;//doesn’t tick the 1st box
var myStr = “FirstLine\n\SecondLine\\rThirdLine”;//ticks all boxes

? your strings the same

3 Likes

You initialise it in same line… Don’t declare in one line and initialize in another line…

2 Likes

The only difference in the second is that the three L’s in line are capital L’s. This drove me insane.

13 Likes

Hi,

There is no difference in escape sequences in these line in order to pass all test cases we must do what exactly they told it means even the string literal also. in your first var myStr the word Thirdline is the problem after you changed what exactly they asked it ticked all the boxes.

1 Like

for anyone that is struggling with this was my answer:

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

14 Likes

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

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

4 Likes

This works totally fine —

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

2 Likes

Thanks! I see know :slight_smile:

1 Like

Working! Spoiler adivise!
var myStr = “FirstLine\n\SecondLine\\rThirdLine”;

var myStr = “FirstLine\n\SecondLine\\rThirdLine”; dis does the work for me after much brainstorming

3 Likes