+ 1
How to display javascript results of in a new line
9 odpowiedzi
+ 4
line 5 : replace with this
document.write(z + "<br>")
+ 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)
+ 2
I'm surprised document.writeln() didn't work
+ 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;
+ 2
You're welcome :)
+ 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.
+ 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;
+ 1
Thanks a lot friends for helping me 🙏
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";
.