freeCodeCamp Challenge Guide: Escape Sequences in Strings

freeCodeCamp Challenge Guide: Escape Sequences in Strings
0

#1

Quotes are not the only characters that can be escaped inside a string. Here is a table of common escape sequences:

Code Output
single quote
" double quote
\ backslash
\n new line
\r carriage return
\t tab
\b backspace
\f form feed

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

The answer is in the sentence it self. ( Backslash the backslash to show the backslash )
So you would need to show a backslash
Here is the text with the escape sequences written out.

FirstLine newline backslash SecondLine backslash carriage-return ThirdLine
var myStr= “Firstline \n \ Secondline \ \r Thirdline” ;

therefore

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


#2

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


#3

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


#4

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


#5

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


#6

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


#7

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


#8

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.


Instructions vague in "Escape Sequences in Strings"
#9
 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?


#10

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


#11

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


#12

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


#13

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.


#14

for anyone that is struggling with this was my answer:

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


#15

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


#16

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


#18

This works totally fine —

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


#19

Thanks! I see know :slight_smile:


#20

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


#21

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