what is wrong with my code in this "Escape Sequences in Strings" challenge on FreeCodeCamp?

11,496

Solution 1

In order to make the challenge work, you're going to need your whole string in quotes and on one line.

So change

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

to

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

Solution 2

valid 2021,2022, 202x URL link to the problem:

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

freeCodeCamp asks for it as console output;

FirstLine
    \SecondLine
ThirdLine

this is the solution to the problem;

var myStr = "FirstLine\n\t\\SecondLine\nThirdLine";
  1. With "\n" we move to the new line.
  2. With "\t" we create a space on the new line.
  3. With "\" we write the \ character on line 2.

sorry for my bad english.

Share:
11,496
Bethany Hible
Author by

Bethany Hible

Updated on June 05, 2022

Comments

  • Bethany Hible
    Bethany Hible almost 2 years

    I can't seem to get past this challenge and it's driving me nuts. I thought I followed the instructions correctly. Can someone please figure out what the error is? (I have a feeling it's something stupidly simple.)

    The challenge is here: https://www.freecodecamp.com/challenges/escape-sequences-in-strings, below is my code.

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

    Thanks in advance!

    Edit: 1st line error: unexpected '\' and missing semicolon; 2nd line error: unexpected '\'; 3rd line error: unexpected '\'