all. I'm new to JavaScript, so hopefully this is a pretty easy question for you all. But I absolutely, for the life of me, cannot figure out how to do this! I'm creating a times table program, and I need the output to look something like this:
5 x 1 = 5
5 x 2 = 10
5 x 3 = 15
...
...and so on. However, whenever it outputs to the screen, it only displays the LAST output from the loop. So it will show "5 x 12 = 60". I need it to show each individual output everytime the program goes through the loop. How would I go about doing this?
Much thanks in advance!
<!DOCTYPE HTML>
<html lang="en-us">
<head>
<meta charset="utf-8">
<!--
Input
User clicks the "Compute Table" button.
Processing
The computer creates a times table based on the users' input.
Output
Outputs the table to the user.
-->
<title>Times Table</title>
<script>
function computeTable() {
// Declaring some variables and pulling the integer from the HTML form. Nothing to see here.
var integer = parseInt(document.getElementById('input').value);
var i = 1;
// Running the loop and doing all the arithmetic
while (i < 12) {
i++;
}
// This line displays the output to the user
var output = document.getElementById('outputdiv');
output.innerHTML = integer + " x " + i + " = " + (integer * i);
}
</script>
</head>
<body>
<h1>Times Table</h1>
Please enter a positive integer: <input type="text" id="input">
<button type="button" onclick="computeTable()">Compute Table</button>
<hr>
<div id="outputdiv" style="font-weight:bold"></div>
</body>
</html>