The correct output should be:
FirstLine
\SecondLine
ThirdLine
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
FirstLine
\SecondLine
ThirdLine
which is correct, while code that was
var myStr = ‘FirstLine\n\SecondLine\\rThirdLine’;
gave an output of
FirstLine
\SecondLine\ThirdLine
Thus, I see that there is an error in the solution to this challenge.
Am I correct?
Link to the challenge:
https://www.freecodecamp.org/challenges/escape-sequences-in-strings