Because you are replacing the innerHTML
all the time, not adding something to it.
To add content, use +=
instead of just =
:
function myFunction() {
var bbb = document.getElementById("ilgis").value;
for (i = 0; i <= bbb; i++) {
//document.writeln(aaa);
document.getElementById("demo").innerHTML += Math.ceil((Math.random() * 10) - 1);
}
}
<input type="number" id="ilgis" value="123">
<button onclick="myFunction()">Click me</button>
<p id="demo"></p>
EDIT:
As @Robin Zigmond stated, it would actually be better to construct a string and append that string to innerHTML
only once after the loop has finished to save performance:
function myFunction() {
var bbb = document.getElementById("ilgis").value;
var numbers = "";
for (i = 0; i <= bbb; i++) {
//document.writeln(aaa);
numbers += Math.ceil((Math.random() * 10) - 1);
}
document.getElementById("demo").innerHTML = numbers;
}
<input type="number" id="ilgis" value="123">
<button onclick="myFunction()">Click me</button>
<p id="demo"></p>