Help with: Escape Sequences in Strings

Help with: Escape Sequences in Strings
0

#1

I’ve been stuck on this and am getting quite frustrated. I can’t figure out what I’m doing wrong! I’ve tried multiple variations of this, changing spacing and no spacing, and haven’t been able to find anyone else that had trouble with this step. Can someone please tell me what I’m doing wrong? Thank you!! :~)


Escape Sequence Javascript
#2

You have semi-colon midway. It should be var myStr = ....


#3

The semi-colon is there on reset:


#4

I tried it anyhow:


#5

There should be a =. So: var myStr = "Firstline\n\\SecondLine\\\r Thirdline;


#6

Hmm, okay. So that worked (thank you!!) but on startup, why does the already inputted text read:

var myStr ;

instead of

var myStr =

Is this just an error?


#7

Glad it worked. var myStr; is just initialising the variable without giving it at a value. var myStr = is incorrect because JS expects a value after the = and also a ;at the end of the line. This would be correct: var myStr = "";.


#8

anyone please help why this is not working

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


#9

A backslash should be escaped as well. So \\ will give you one backslash.


#10

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

This was confusing as hell for me and I still don’t quite get it to be perfectly honest. Javascript in general is killing me so far. Good luck!


#11

Mine doesn’t work and I can’t figure it out for the life of me, I don’t get it help plox. I have it written as:
var myStr=“FirstLine\n \\SecondLine\\ \rThirdLine”;


#12

@JonathanTwins

You’re almost there. I believe the spaces are what’s causing it not to pass. I think if you remove the spaces after \n and before \rThirdLine"; you’ll be set.


#13

This worked for me.

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

So new line ===\n
backslash === double \
carriage return ===\r


#14

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

why the hell not wrking…?


#15

You haven’t escaped backslashes.


#16

Ya i Got It later… Thanks(:slight_smile:


#17

Thanks for posting, I needed the help! :slight_smile:


#18

this one works

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


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

This is correct one . should be double backslash rather than \


#20

I Completed this exercise by using this
var myStr=“FirstLine\n\SecondLine\\rThirdLine”;

I can’t understand the difference between \n and \r
why \r before ThirdLine (why not \n here also)
can anyone explain
thanks in advance