+ 2

Why won't my JavaScript code line break?

Hi all, I'm currently writing my first code in code playground. It's really simple, just the Old MacDonald had a farm rhyme with a couple simple functions. However, the output is currently all in one paragraph and I nothing I do will break it. I've tried \n, and "\n" both in the the middle of a string and at at the end neither will work. I've tried looking it up, but all the sources say to use the break <br> tag, which doesn't work because I'm not using any html. Help please! it's my first code!

16th Dec 2016, 5:38 AM
Hannah T
Hannah T - avatar
5 Respuestas
+ 4
Try this : document.write("Old Macdonald </br>had a farm.") You can always style the text inside the parentheses by adding html tags. It would then be something like : window.onload = function song() { document.write("lyrics over here </br> over here too") ; }
16th Dec 2016, 7:06 AM
David Sebastian Keshvi Illiakis
David Sebastian Keshvi Illiakis - avatar
+ 3
(edit) Actually, <br> or \n SHOULD work.
16th Dec 2016, 6:40 AM
Karl T.
Karl T. - avatar
+ 3
if you want to keep \n linebreak you can wrap your text into <pre>my message \n is here </pre> tag
19th Dec 2016, 7:13 AM
wave rider
+ 2
thank you Nicholas and Karl! I discovered the reason the break tag wasn't working was because it wasn't enclosed in quotes, but now it works! feel free to check the code out, too! any comments or suggestions are appreciated!
16th Dec 2016, 9:44 PM
Hannah T
Hannah T - avatar
- 2
it's /n not the other way
16th Dec 2016, 6:03 AM
Ian
Ian - avatar