Escape Sequences in Strings SecondLine\\

So after literally two hours of fighting with this challenge. And took break clear my mine and went back to it. Looked at a few people code on here, and re-read the instruction thoroughly. I end up getting it to work. Unless there’s something wrong with the instruction or the challenge decide to take the answer as is. Because one of the steps in the instruction says
SecondLine should be preceded by the backslash character \
But I remove the \ after SecondLine and it works fine. So I’m not sure!! So here’s my answer below!!

var myStr = “FirstLine\n\t\SecondLine\nThirdLine”;

I’m not sure if \S is a valid escaped char! Maybe you mean \\?

You may also share the challenge link too, thanks.

I did not saying anything about \S. I was talking about \ the backslash escaped character which the instruction told us to insert in between of SecondLine and ThirdLine. But when inserted the \ my code failed. When I remove it my code pass.

https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/escape-sequences-in-strings/

This is because of escaping. When browser reaches a \ it expect the next character is a meaningful(known) char so it could render/use.

Here your code fails of course, becasue once browser reaches \S it finds it faulty, simple becasue there is no \S!

Challenge needs you to put a \ as char between the tab and SecondLine. \ itself should be escaped, so easy, as we escape double-quote by inserting a \ before it like “We love “double-quote”?!”, same for \ itself, it’s \\ try it.

Again I think you’re reading it wrong. I was never talking \S. I was talking about \. Where did you get \S from there’s no \S escape character.

@NULL_dev is refering to the \S you have in the string you assigned to the variable myStr (shown above).

I just point out to you input

Again, please note \S is wrong.

This is just like you write “Knight”, but you don’t pronounce “K”.

So you talk(what challenge says) “place one backslash \ at the end”. It doesn’t mean you just paste what it says, you need to escape it pal, so JS could understand. If it says it needs a backslash , o it hsould be placed escaped, becasue \ is a special char.

Just what you did for tab and newline, do the same for .

It’s not a \S. It’s \SecondLine.
I was explaining why my code wasn’t working after trying everything and how did I got it to work.
See my code below!
var myStr = “FirstLine\n\t\SecondLine\nThirdLine”;

You actually just got lucky, because your code does not actually create the required output, but passes the tests, which means the test has a bug which needs to be fixed. I will report the bug on github it is not already reported.

Your code actually assigns the following to myStr

FirstLine
	SecondLine
ThirdLine

and it should assign:

FirstLine
	\SecondLine
ThirdLine

You are missing an extra \ before the \SecondLine to get the \ to show. It appears that JavaScript just ignores the \ because \S is not a special code of any sort.

UPDATE: The bug in the test I mentioned above has already been reported on github (see below).

https://github.com/freeCodeCamp/freeCodeCamp/issues/17712

That is exactly what I said in my very first post. In my first post, I said and I quote “Unless there’s something wrong with the instruction or the challenge decide to take the answer as is”. So I was right there is a bug. I kind of knew that. So I’m not sure where was @NULL_dev was getting \S from my posts. So at @RandellDawson how would you write it base on the instruction? I added the \ it did not take it, but when I remove it, it accepeted it very strange.

The solution which should pass (but does not because of the bug in the test) is:

var myStr = "FirstLine\n\t\\SecondLine\nThirdLine";

I apologize for not reading your original post more closely. I should have caught the fact that you were trying to write the correct code but the test was incorrectly rejecting it.

I just notice that and re did my code see below

var myStr = “FirstLine\n\t\SecondLine\nThirdLine”;

oh damn as I was writing my new code and your message pop up. But I figure it out after I went back to my code. But it’s weird that it accepted it without the \SecondLine the first time.