# Escape Sequences in Strings - new line

**URL:** <https://forum.freecodecamp.org/t/escape-sequences-in-strings-new-line/110784>\
**Category:** General\
**Created:** [April 30, 2017, 5:31am UTC](https://forum.freecodecamp.org/t/escape-sequences-in-strings-new-line/110784 "2017-04-30T05:31:15Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![tomer-n](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/tomer-n/32/71826_2.png) [@tomer-n](https://forum.freecodecamp.org/u/tomer-n)\
**Post date:** [April 30, 2017, 5:31am UTC](https://forum.freecodecamp.org/t/escape-sequences-in-strings-new-line/110784/1 "2017-04-30T05:31:16Z")

</div>

hello.

I am at the javascript course in the Escape Sequences in Strings lesson.

is this the right way to make a new line?

var myStr = “FirstLine \n SecondLine ThirdLine”;

---

<div class="post-metadata">

**Author:** ![MohammedBm](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/mohammedbm/32/196748_2.png) [@MohammedBm](https://forum.freecodecamp.org/u/MohammedBm)\
**Post date:** [April 30, 2017, 5:34am UTC](https://forum.freecodecamp.org/t/escape-sequences-in-strings-new-line/110784/2 "2017-04-30T05:34:49Z")

</div>

If i remember correctly you don’t need the “n” after the “” sign.

---

<div class="post-metadata">

**Author:** ![kevinSmith](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/kevinsmith/32/72934_2.png) [@kevinSmith](https://forum.freecodecamp.org/u/kevinSmith)\
**Post date:** [April 30, 2017, 6:53am UTC](https://forum.freecodecamp.org/t/escape-sequences-in-strings-new-line/110784/3 "2017-04-30T06:53:51Z")

</div>

Well, per the instructions, there should be no spaces.

You will need four escape sequences, the first is the new line (which as you have is _\n_) and then an escape sequence for each of the backslashes they want, and a final one for the carriage return. Again, **there must be no spaces in your string**.

---

<div class="post-metadata">

**Author:** ![michaelkeen](https://avatars.discourse-cdn.com/v4/letter/m/7ba0ec/32.png) [@michaelkeen](https://forum.freecodecamp.org/u/michaelkeen)\
**Post date:** [April 30, 2017, 11:35am UTC](https://forum.freecodecamp.org/t/escape-sequences-in-strings-new-line/110784/4 "2017-04-30T11:35:26Z")

</div>

You do use it the right way ,’\n’ for a new line but you shouldn’t use spaces in the string. Watch out for those kind of errors that can hurt your code. They are hard to be detected and can spend a lot of your time. If you need some help detecting errors, you can try using some programs like checkmarx or others. They work pretty good I guess. But if you’re new to programming it’s recommended to learn how to do it also by yourself.  
Good luck!  
Michael.

---

<div class="post-metadata">

**Author:** ![tomer-n](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/tomer-n/32/71826_2.png) [@tomer-n](https://forum.freecodecamp.org/u/tomer-n)\
**Post date:** [April 30, 2017, 11:59am UTC](https://forum.freecodecamp.org/t/escape-sequences-in-strings-new-line/110784/5 "2017-04-30T11:59:15Z")

</div>

thanks Michael,

i tried withoput spaces and stild doesn’t work:

 ![](https://global.discourse-cdn.com/freecodecamp/original/3X/a/3/a3c9fb57b10b03a409c316a95408da991a1f88c8.png)

---

<div class="post-metadata">

**Author:** ![kevinSmith](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/kevinsmith/32/72934_2.png) [@kevinSmith](https://forum.freecodecamp.org/u/kevinSmith)\
**Post date:** [May 1, 2017, 1:34am UTC](https://forum.freecodecamp.org/t/escape-sequences-in-strings-new-line/110784/6 "2017-05-01T01:34:28Z")

</div>

Can you please cut and paste the string you are trying to do?

Is that your string, _“first\n second”_?

first of all, your string should start out as _"FirstLine\nSecond…_ then it must continue on.

The capitalization needs to be exactly the same, there must be no spaces and when you see “FirstLine”, that is meant to be exact. where the text is in red, that is meant to be escape sequences.

Think of it this way, the base string is _“FirstLineSecondLineThirdLine”_. Then you need to insert four escape sequences in there, one for new line, two for backslashes, and one for a carriage return.

If you get stuck, cut and paste your string here and we can help.

---

<div class="post-metadata">

**Author:** ![tomer-n](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/tomer-n/32/71826_2.png) [@tomer-n](https://forum.freecodecamp.org/u/tomer-n)\
**Post date:** [May 1, 2017, 5:50am UTC](https://forum.freecodecamp.org/t/escape-sequences-in-strings-new-line/110784/7 "2017-05-01T05:50:21Z")

</div>

thanks mate, i still don’t understand where is my mistake:

 ![](https://global.discourse-cdn.com/freecodecamp/original/3X/8/c/8cee9e94d4025ef25fcc10422e43f17d5f688cfb.png)

---

<div class="post-metadata">

**Author:** ![kevinSmith](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/kevinsmith/32/72934_2.png) [@kevinSmith](https://forum.freecodecamp.org/u/kevinSmith)\
**Post date:** [May 1, 2017, 6:57am UTC](https://forum.freecodecamp.org/t/escape-sequences-in-strings-new-line/110784/8 "2017-05-01T06:57:33Z")

</div>

I don’t want to _give_ you the answer, but you’re making progress.

The new line is in the correct place and so is the second backslash. And there are no spaces.

Looking at the requirements, you need a backslash after the newline (before “SecondLine”). Also, the escape sequence for the carriage return needs to be _before_ “ThirdLine”, not _after_.

So, if you add in that backslash escape after “FirstLine” and move the carriage-return escape, you should be set.

Remember that the red letters in the suggestion tell you _exactly_ where those things are supposed to go. Any deviation from that will fail.

Let us know if you still have issues.

---

<div class="post-metadata">

**Author:** ![lionel-rowe](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/lionel-rowe/32/41877_2.png) [@lionel-rowe](https://forum.freecodecamp.org/u/lionel-rowe)\
**Post date:** [May 2, 2017, 12:22am UTC](https://forum.freecodecamp.org/t/escape-sequences-in-strings-new-line/110784/9 "2017-05-02T00:22:07Z")

</div>

Your printed output would currently be:

```auto
"FirstLine
SecondLine\ThirdLine
"

```

(With first line break being a newline and second being a carriage return)

---

<div class="post-metadata">

**Author:** ![Soupedenuit](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/soupedenuit/32/32478_2.png) [@Soupedenuit](https://forum.freecodecamp.org/u/Soupedenuit)\
**Post date:** [May 2, 2017, 4:35am UTC](https://forum.freecodecamp.org/t/escape-sequences-in-strings-new-line/110784/10 "2017-05-02T04:35:54Z")

</div>

May I suggest you use the search feature within FCC prior to posting a question that has been addressed many times?

[https://forum.freecodecamp.com/search?q=escape%20sequences](https://forum.freecodecamp.com/search?q=escape%20sequences)

---

<div class="post-metadata">

**Author:** ![tomer-n](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/tomer-n/32/71826_2.png) [@tomer-n](https://forum.freecodecamp.org/u/tomer-n)\
**Post date:** [May 2, 2017, 8:24am UTC](https://forum.freecodecamp.org/t/escape-sequences-in-strings-new-line/110784/11 "2017-05-02T08:24:06Z")

</div>

thanks mate, it is ok now

---

<div class="post-metadata">

**Author:** ![tomer-n](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/tomer-n/32/71826_2.png) [@tomer-n](https://forum.freecodecamp.org/u/tomer-n)\
**Post date:** [May 2, 2017, 8:24am UTC](https://forum.freecodecamp.org/t/escape-sequences-in-strings-new-line/110784/12 "2017-05-02T08:24:32Z")

</div>

thanks for the help, i got it

---

<div class="post-metadata">

**Author:** ![Alex1](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@Alex1](https://forum.freecodecamp.org/u/Alex1)\
**Post date:** [September 15, 2017, 9:39pm UTC](https://forum.freecodecamp.org/t/escape-sequences-in-strings-new-line/110784/13 "2017-09-15T21:39:11Z")

</div>

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

this is not working for me, what am i doing wrong. All boxes checked except for first one.  
Please Help

---

<div class="post-metadata">

**Author:** ![Alex1](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@Alex1](https://forum.freecodecamp.org/u/Alex1)\
**Post date:** [September 15, 2017, 9:41pm UTC](https://forum.freecodecamp.org/t/escape-sequences-in-strings-new-line/110784/14 "2017-09-15T21:41:13Z")

</div>

I c/p my code and it deleted slashes automatically?? WTF.

var myStr = “FirstLine\n\SecondLine\\rThirdLine”;  
is what I have. Not working.

---

<div class="post-metadata">

**Author:** ![Alex1](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@Alex1](https://forum.freecodecamp.org/u/Alex1)\
**Post date:** [September 15, 2017, 9:43pm UTC](https://forum.freecodecamp.org/t/escape-sequences-in-strings-new-line/110784/15 "2017-09-15T21:43:57Z")

</div>

wow, i literally typed my code in with all proper slashes and characters and when I hit reply, what shows up is not what I typed. WTF is going on here?  
“FirstLine slash n slash slash SecondLine slash slash slash r ThirdLine”;

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 16, 2021, 5:51pm UTC](https://forum.freecodecamp.org/t/escape-sequences-in-strings-new-line/110784/16 "2021-01-16T17:51:42Z")

</div>

Closed on January 16, 2021, 5:51pm UTC


