I'm trying to create a webpage where the user inputs the limit for a counter, which starts at 0. When the user enters a number and clicks the button, the web page will display all the numbers from 0 up to the limit entered.
The following is the JavaScript code I have so far however it wont run properly.
function display() {
var num = document.getElementbyId("UserIN").value;
num = parseInt(num);
var counter = 0;
while (counter <= num) {
document.getElementById("outdisplay").innerHTML += counter + "<br/>";
counter += 1;
}
}
<input type="number" id="UserIN">
<button onclick="display()">Run</button>
<div id="outdisplay"></div>
function display(inputElement, outputElement) {
var num = parseInt(inputElement.value);
var counter = 0;
// Loop from 0 to number
for (counter; counter < num; counter++) {
outputElement.innerHTML += `${counter}<br/>`;
}
}
Is that what you want?