Need help in "Basic JavaScript: Escape Sequences in Strings"

Tell us what’s happening:

I have two mistakes that need to be solved. First, is second lineshould be preceded by the backslash character `. And the second one is myStr should only contain characters shown in the instructions.

Your code so far


var myStr = "FirstLine
\tSecondLine
ThirdLine"; // Change this line

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36.

Challenge: Escape Sequences in Strings

Link to the challenge:

You can’t put things on multiple lines by putting the string on multiple lines. That’s one of the things that the challenge is trying to explain. You need to use the “newline” escape sequence.
You also didn’t put an escaped backslash in your code.

Here is the text with the escape sequences written out.

“FirstLine newline tab backslash SecondLine newline ThirdLine”

You need to replace those highlighted bits with the corresponding escape sequence.

FirstLine\n\tSecondLine\nThirdLine This is what I put is it wrong?

Still no backslash.

FirstLine\n\t\\SecondLine\nThirdLine

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

Note: Backticks are not single quotes.

markdown_Forums

I know about Preformatted text I just forgot to put it. And on the topic of this why doesn’t any changes happen to this following text then I add \n. \t, etc. e.g. var a = "Hello\nWorld", why isn’t there a new line, between Hello and world?

I’m not sure what you mean. It will put a newline in.

1 Like

Thanks, I figured out how to use \ properly.

Good job! Happy coding.