0

How to add a space between document.write()

The issue is that whenever I create a new document text like: var x = 100; var y = x + 500+300+100; document.write(y); document.write("Testing the space separator"); I get this "1000Testing the space separator" for example. How should I proceed? Thanks

31st Jul 2018, 6:09 PM
Lazaro Carrillo
Lazaro Carrillo - avatar
8 ответов
0
From this you can use space anywhere var z = "<br>"; var x = 100; var y = x + 500+300+100; document.write(y); document.write(z); document.write("Testing the space separator");
31st Jul 2018, 10:12 PM
Daniyal Suhail
Daniyal Suhail - avatar
+ 7
use \n after y or before testing
31st Jul 2018, 7:10 PM
LONGTIE👔
LONGTIE👔 - avatar
+ 2
You got 2 more options, putting the space in the second write: var x = 100; var y = x + 500+300+100; document.write(y); document.write(" Testing the space separator"); Or, add another write: var x = 100; var y = x + 500+300+100; document.write(y); document.write(" "); document.write("Testing the space separator");
31st Jul 2018, 7:00 PM
John Wells
John Wells - avatar
+ 1
To get on the next line, write some HTML. document.write("<br>");
31st Jul 2018, 7:02 PM
John Wells
John Wells - avatar
+ 1
Thanks, John and TurtleShell, the document.write("<br>") did the trick.
31st Jul 2018, 7:21 PM
Lazaro Carrillo
Lazaro Carrillo - avatar
+ 1
var z = "<br>"; var x = 100; var y = x + 500+300+100; document.write(y + z); document.write("Testing the space separator");
31st Jul 2018, 10:14 PM
Daniyal Suhail
Daniyal Suhail - avatar
0
document.write(y + " "); or a newer JS feature called string templates/interpolation (for this case probably an overkill) document.write(`${y} `);
31st Jul 2018, 6:21 PM
TurtleShell
TurtleShell - avatar
0
Thanks for that but if I want to set it like 1000 Testing the space separator What should I use?
31st Jul 2018, 6:47 PM
Lazaro Carrillo
Lazaro Carrillo - avatar