Javascript-Session 2-Multiplication Table 3
A multiplication table where the number of rows are randomly generated from a number between 10 and 20 by passing on the variable RandomNumRow; and columns from 1 to 5 by passing on the variable RandomNumCol. Here is the link, refresh to generate new numbers.
<html>
<body>
<script language=”JavaScript”>
document.write(’<table border=0>’);
//—creates random number for rows—
minimum = 10;
max = 20;
numb = genRand(minimum, max); //—call function, pass and receive data—
function genRand(min, max) //—function that accepts 2 parameters—
{
rand = Math.random( ) * (max-min+1)
rand = Math.floor(rand) + min
return(rand) //—function return data to calling code—
}
var randomNumRow=numb
//—
//—creates random number for columns—
minimum = 1;
max = 5;
numb = genRand(minimum, max);
function genRand(min, max)
{
rand = Math.random( ) * (max-min+1)
rand = Math.floor(rand) + min
return(rand)
}
var randomNumCol=numb
//—
//—creates index(red) row ‘X’ through number determined by “var randomNumCol”—
document.write(’<tr style=color:red>’);
document.write(’<td>’+'X’+'</td>’);
for (row1=1; row1<=randomNumCol; row1++)
{
document.write(’<td>’+row1+’</td>’);
}
document.write(’</tr>’);
//—
var col1=1
for (row=1; row<=randomNumRow; row++)
{
document.write(’<tr>’);
//—creates index(red) column—
document.write(’<td style=color:red>’+col1+++’</td>’);
//—
for (col=1; col<=randomNumCol; col++)
document.write(’<td>’+col*row+’</td>’);
document.write(’</tr>’);
}
document.write(’</table>’);
</script>
</table>
</body>
</html>