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
3 Respuestas
+ 2
Use writeln() instead of write().
document.writeln();
+ 1
@Restoring Faith, is it valid. I don't think so.
Better use \n.
This is not Java.
+ 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.