Error in "Escape Sequences in Strings"?

The correct output should be:


and the corresponding code should be

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

However, I didn’t understand why carriage return was used in place of a newline. In my opinion, I thought that the correct code should be

var myStr = 'FirstLine\n\\SecondLine\\\nThirdLine'; //Change this line

To further check the validity of the two pieces of code, I added console.log(myStr); after the code and used Chrome’s Developer Tools (Ctrl+Shift+I) --> Console to see the output of myStr.

As a result, code that was
var myStr = ‘FirstLine\n\SecondLine\\nThirdLine’;
gave an output of

which is correct, while code that was

var myStr = ‘FirstLine\n\SecondLine\\rThirdLine’;
gave an output of


Thus, I see that there is an error in the solution to this challenge.
Am I correct?

Link to the challenge:

It may not necessarily be an error.

In my Safari console I get the following:

> "a\nb"
> a
> b
> "a\rb"
> ab

While in the I get this:

> a
> \b\
> c

I think it’s just the difference of behavior between \n and \r and how it is dealt with in browsers. What the question asks for isn’t necessarily wrong, it’s just not consistently that way everywhere.

Maybe the big take away is … don’t use carriage return to make a new line! :slight_smile: (Which you learned!)

I believe that there is a difference because carriage return works differently in Linux and Windows.

Also, I didn’t mean that there was an error. I was just asking whether the solution was incorrect, because the last time I checked, carriage return would return the pointer to the beginning of the line, and not to a new line, like \n does and what our output needs.

\b\ (\n)