0

Give the break or new line of last two output statements

function person (name,age,color) { this.name = name; this. age = age; this.color = color; } var p1 = new person("John", 42, "Green"); var p2 = new person(" avi",21,"Pink"); document. write(p1.age); document.write(p2.name); output: 42Avy But Output Should be in : 42 Avy

25th Jun 2017, 3:36 AM
R HARI KRISHNA
R HARI KRISHNA - avatar
3 ответов
+ 2
Use writeln() instead of write(). document.writeln();
25th Jun 2017, 5:15 AM
Rrestoring faith
Rrestoring faith - avatar
+ 1
@Restoring Faith, is it valid. I don't think so. Better use \n. This is not Java.
25th Jun 2017, 7:35 AM
Dragon Slayer Xavier
Dragon Slayer Xavier - avatar
+ 1
@Amrit Ah, thanks for bringing that up, turns out it doesn't appear on a new line since whitespace is collapsed when the html renders. That also means \n isn't going to work btw, atleast under the context that writeln() won't work. Here's a code of them working anywho: https://code.sololearn.com/W0v1Hl2NhQlv/?ref=app @Kiraaq Better to use <br \> to move to the next line in html then. Example/ document.write("Example<br \>Next line."); Or I guess you could just do <br> without the \. Shorter to write.
25th Jun 2017, 4:53 PM
Rrestoring faith
Rrestoring faith - avatar