+ 1

How to display javascript results of in a new line

https://code.sololearn.com/W8DXUSv6rp6M/?ref=app

2nd Sep 2021, 5:57 PM
Niraj Kori
Niraj Kori - avatar
9 odpowiedzi
+ 4
line 5 : replace with this document.write(z + "<br>")
2nd Sep 2021, 6:05 PM
Pariket Thakur
Pariket Thakur - avatar
+ 4
You can use <br /> //your code goes here var x=10; var y=20; var z=x*y; var a=y/x; document.write(z + "<br />") document.write(a)
2nd Sep 2021, 6:05 PM
Rupali Haldiya
Rupali Haldiya - avatar
+ 2
I'm surprised document.writeln() didn't work
2nd Sep 2021, 6:21 PM
Tim
Tim - avatar
+ 2
The finest way Niraj Kori will be your code to extend in this way: document.querySelector('body').innerHTML = 'x = ' + x + '<br>' + 'y = ' + y + '<br>'; document.querySelector('body').innerHTML += 'x * y = ' + z + '<br>' + 'y / x = ' + a;
2nd Sep 2021, 8:16 PM
JaScript
JaScript - avatar
+ 2
You're welcome :)
3rd Sep 2021, 8:22 AM
Rupali Haldiya
Rupali Haldiya - avatar
+ 2
Please don't use document.write to send results out, it's totally useless method in Javascript web development. Learn to use document.getElememtById or querySelector methods to have any web content updates.
4th Sep 2021, 4:38 AM
Calviղ
Calviղ - avatar
+ 1
let x=10, y=20; let t = `x = ${x} <br> y = ${y} <br> ` + `x * y = ${x*y} <br>` + `x / y = ${x/y} <br>` + `y / x = ${y/x} `; document.querySelector('body').innerHTML = t;
2nd Sep 2021, 9:42 PM
SoloProg
SoloProg - avatar
+ 1
Thanks a lot friends for helping me 🙏
3rd Sep 2021, 4:11 AM
Niraj Kori
Niraj Kori - avatar
0
You can also use <p> tag, it will automatically break to new line, also avoid using document.write("foo"), instead use element.textContent = "foo"; .
4th Sep 2021, 4:13 PM
Xuro
Xuro - avatar