0
[Solved] How do i change line in JS result ?
Hello ! solo learners, i got an issue i write some general codes in the below link. I want to know how do i change the line of the results. I already know "\n" is used to creat a new line ( but it doesn't work in variables ) . If you know the solution plz let me know THANK YOU 🍫 https://code.sololearn.com/WXm7B6Wsxbp1/?ref=app
3 Respuestas
+ 11
document.write(x + "</br>");
document.write(y+"</br>");
+ 1
Thanks bro it works !
+ 1
when you console.log(), you output (print) to web browser console, so output is done as expected (with new line char "\n" introducing a new line in output)...
conversely, when you document.write(), output is appended to currect web (html) document, and is parsed as rest of html/css/js source code: that's why you require either "<br>" to replace "\n" OR to use style/tag wich do not follow html default behavior for spaces-like characters (treat all including new lines as space, and collapse contiguous ones to only one or zero space -- if at start or end of block content):
so another solution could be:
document.write("<pre>"+text_including_new_lines+"</pre>");
but you should be aware that's more safe to escape dangerous characters, as in html source code: at least "<" with "<" and "&" with "&" ^^