Whats wrong with this line of code, cant seem to figure it out

Whats wrong with this line of code, cant seem to figure it out
0

#1
var myStr="\"FirstLine\"\n\\\"SecondLine\"\\\r\"ThirdLine\"";

#2

First thing I can see is the end of it. You can’t have two " next to each other.


#3

One possible solution is to make the first and last quotr single quotes. This gets you a little bit closer.


#4

I cleaned up your code.
You need to use triple backticks to post code to the forum.
See this post for details.

What errors are you getting with this line?


#5

i take it your trying to have 3 quoted lines of text … one on each line … this i how i changed yours

var myStr='\"FirstLine\"\n\"SecondLine\"\r\"ThirdLine\"';

“FirstLine”
“SecondLine”
“ThirdLine”


#6

All of the quotes are escaped, so the string is valid with single or double quotes. The \r may be what is causing unexpected behavior - that is, a lack of behavior as it won’t make a new line.

But this is speculation until we know what the issue actually is.


#7

noticed that about the r … gives a new line in repl.it and phytontutor … but not if you do it in the console.
im persuming the issue is the second line of his code is printing … “SecondLine”\ and he dosent want the \ showing


#8

tis was the error

myStr should have encoded text with the proper escape sequences and no spacing.


#9

those are supposed to show


#10
var myStr='\"FirstLine\"\n\\\"SecondLine\"\\\r\"ThirdLine\"'; // Change this line

this still not working.


#11

Why are you being inconsistent with the usage of your carrier return?
You’ve got \n in one instance and \r in the other. You’re trying to achieve the same thing twice, which is to break twice.

This works: var myStr = '\"FirstLine\"\n\"SecondLine\"\n\"ThirdLine\"';
if you’re trying to achieve:
“First Line”
“Second Line”
“Third Line”

Is that the case?


#12

Hi the challenge demands one \n and one carrier return


#13

Which challenge? Link?


#14

SPOILER!!!

Ok I see. I found it.
This was my solution
var myStr = "FirstLine\n\\SecondLine\\\rThirdLine";


#15

Thanks man that works