Java Script


JavaScript Tutorial


Admission Enquiry Form


Generate a table of number taken in variable.

Example :

<html>
<head>
<title>Generate table of a number using for loop</title>
</head>

<body>
<script>
var num,i,k;
num=2; //number of which the table has to be generated
for(i=1;i<=10;i++)
{
k=num*i;
document.write(num+" * "+i+" = "+k+"<br>");
}
</script>
</body>
</html>

Generate a table of number entered using prompt() function

Example:

<html>
<head>
<title>Generate table of a number entered in prompt() using for loop</title>
</head>

<body>
<script>
var num,i,k;
num=parseInt(prompt("Enter a number"));
for(i=1;i<=10;i++)
{
k=num*i;
document.write(num+" * "+i+" = "+k+"<br>");
}
</script>
</body>

</html>


Generate a table of number entered on Button click using function.

Example:

<html>
<head>
<title>Generate table of a number entered on Button click using function</title>
<script>
function table()
{
var num,i,k;
num=parseInt(prompt("Enter a number"));
for(i=1;i<=10;i++)
{
k=num*i;
document.write(num+" * "+i+" = "+k+"<br>");
}
}//end of table
</script>
</head>

<body>
<input type="button" value="click" onClick="table()">
</body>
</html>