Escape Sequences in Strings challenge

Escape Sequences in Strings challenge
0.0 0

#1

the “Escape Sequences in Strings” challenge requires this output :

FirstLine
\SecondLine
ThirdLine

this is my code:

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

however, I got this output:

“FirstLine\n\SecondLine\\rThirdLine” , exactly as I wrote it inside the single quote.

questions:
why didn’t \n give me a newline for \SecondLine?
where did the double quote at the two ends of the output come from?
why was the extra \ after \SecondLine\ included in the output?
finally, why \r was printed? or rather, what does \r do normally in JavaScript?

Hope some answers from my fellow campers!
Thanks


#2

When I try testing your code, it passes.


#3

Thanks Ariel for your reply.

I know the code is working but I have asked several questions on the issue as follows:
questions:
why didn’t \n give me a newline for \SecondLine?
where did the double quote at the two ends of the output come from?
why was the extra \ after \SecondLine\ included in the output?
finally, why \r was printed? or rather, what does \r do normally in JavaScript?

if you could look at it would be helpful. thanks again.


#4

why didn’t \n give me a newline for \SecondLine?

  • It did. See below.

where did the double quote at the two ends of the output come from?

  • When the FCC tests ran, your assigned value for the variable was shown. FCC uses double quotes rather than single quotes by default. There is no difference between the two strings.

why was the extra \ after \SecondLine\ included in the output?

  • It wasn’t. See below.

finally, why \r was printed? or rather, what does \r do normally in JavaScript?

  • It wasn’t. See below.


#5

Thank you so much Ariel for simplifying the answer. I got it.