+ 2
\n doesn't work
I'm messing around on javascript, and I find that \n and <br> do not work. what do I use to start a new line? thank you for any comments yall leave
11 Réponses
+ 3
To see the new line in html you would use <br>.
To see the new line in things like the console, use \n. (Anything that isn't rendered by the html page).
Can I see your code that has both not working? Perhaps your browser is not updated?
+ 3
That's fine we all start somewhere, I think I was around 15 when I was first introduced to programming. I had absolutely no idea what was going on lol.
\n is actually by itself NOT a statement. To simplify this for you, it is something that goes inside a string which will say to move to the next line.
So your code could be like this:
var x = 10;
document.write(x + "\n");
That will be how it's properly used.
If that doesn't work, use "<br>" instead of "\n". But keep the + !
+ 2
what is your browser ? try \r\n
+ 2
@josh
no heh, I'm actually Atheist (or agnostic-atheist, not sure what people call it anymore).
Originally I was planning on creating motivational/inspirational videos on Youtube so came up with this as a name. Although, I never really followed through (Made some, but they weren't great so I removed them).
I still kept the name though. It still fits well anyway! 😜
+ 1
Can you provide a link to the code?
+ 1
wow thx. yeah i really don't know what I'm doing. I'm also trying to learn linux, which is very different, but I like JS language more. I am happy to get a sentence on the output without screwing it up, so anything yall say will help. thank you
+ 1
Since you are using the Document.write() nethod, which injects into the HTML document, you will probably want to use <BR />. Your code should look like
document.write(x + "<BR />") ;
PS don't worry about being new, young and not knowing stuff you have plenty of time to learn. 😃
+ 1
@Restoring faith, are you a Christian?
+ 1
OK just wondering because I am.
0
I was using the JS that came with this app.
var x = 10;
document.write(x);
\n;
var y = x + 10;
document.write(y)
I would like to say I am very new to all this. I'm just a 15 year old kid looking to learn the basics. I'm pretty much a super noob.
but yeah there's my code if I did something wrong I'm happy to hear it. thx yall
0
I am a Pentecostal Christian.