Through JavaScript you can easily write the html code in html document using document.write(). Using document.write() and for loop it is easy to print the table of user input number.

First of all “promt” box will appear and then this value will be parse to integer and the multiplication table is displayed.

The source code for JavaScript is as follows:

<script type='text/javascript'>
var num = prompt("Enter Number", "0") //prompt user to enter the number
var num = parseInt(num); //parse the num to number
var i = 0;
document.write('<table border="1" cellspacing="0">');
for(i=1;i<10;i++) {
document.write("<tr><td>" + num + " x " + i + " = " + num*i + "</td></tr>");
}
document.write("</table>");
</script>

### Like this:

Like Loading...

John W Driscoll

said:Reblogged this on johnwdriscoll.

afafshaa

said:nice very usefull

Pat Erickson

said:the above code is not a true multiplication table, it’s simply showing the multiples of the number you type. Below would be a true multiplication table:

Multiplication Table

document.write(”);

function multiply() {

var col, row, answer, multiplier; //declare variabels

document.write(‘Multiplication Table’ + ”);

document.write(‘Refresh the browser to use a different table multiplier’ + ”);

multiplier = prompt(“Enter a Multiplication Table max multiplier, ie; 10 for 10×10”, “”)

multiplier = parseInt(multiplier); //parse the num to number

document.write(”); //setup the table

for( col = 1; col <= multiplier; col++) {

document.write('’ + ‘ ‘);

for( row=1; row <= multiplier; row++) {

answer = col * row; //multiply columns * rows, store in variable answer

document.write( '’ + ‘ ‘ + answer + ‘ ‘ + ”);

}

document.write(”);

}

document.write(”);

}

document.write(”);

window.onload = multiply;

anil prasanna

said:thank you it useful for us