freeCodeCamp Challenge Guide: Escape Sequences in Strings

freeCodeCamp Challenge Guide: Escape Sequences in Strings
0

Escape Sequences in Strings


Solutions

Solution 1 (Click to Show/Hide)
var myStr = "FirstLine\n\t\\SecondLine\nThirdLine";
4 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

2 Likes

var myStr =‚ÄúFirstLine\n\SecondLine\\rThirdLine‚ÄĚ;

Try this code:
var myStr = ‚ÄúFirstLine\n\SecondLine\\rThirdLine‚ÄĚ;

var myStr= ‚ÄėFirstLine\n\\SecondLine\\rThirdLine‚Äô;

3 Likes

var myStr= ‚ÄėFirstLine\n\SecondLine\\rThirdLine‚Äô;

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.

63 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

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

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

11 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.

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‚ÄĚ;

This works totally fine ‚ÄĒ

var myStr=‚ÄúFirstLine\n\SecondLine\\rThirdLine‚ÄĚ;

Thanks! I see know :slight_smile:

Working! Spoiler adivise!
var myStr = ‚ÄúFirstLine\n\SecondLine\\rThirdLine‚ÄĚ;

var myStr = ‚ÄúFirstLine\n\SecondLine\\rThirdLine‚ÄĚ; dis does the work for me after much brainstorming