Help with: Escape Sequences in Strings

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!! :~)

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

The semi-colon is there on reset:

I tried it anyhow:

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

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?

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 = "";.

1 Like

anyone please help why this is not working

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

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

1 Like

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!

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”;

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

1 Like

This worked for me.

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

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

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

why the hell not wrking…?

You haven’t escaped backslashes.

Ya i Got It later… Thanks(:slight_smile:

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

this one works

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

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

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

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