+ 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!
5 odpowiedzi
+ 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") ;
}
+ 3
(edit) Actually, <br> or \n SHOULD work.
+ 3
if you want to keep \n linebreak you can wrap your text into <pre>my message \n is here </pre> tag
+ 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!
- 2
it's /n not the other way