Javascript-Session 2-Multiplication Table 2
A multiplication table where the number of rows and columns are randomly generated from a number between 1 and 10 by passing on the variable RandomNum. Here is the link, refresh to generate a new number.
<html>
<body>
<script language=”JavaScript”>
document.write(’<table border=0>’);
minimum = 1;
max = 10;
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 randomNum=numb
//—creates index(red) row ‘X’ through number set in “var randomNum”—
document.write(’<tr style=color:red>’);
document.write(’<td>’+'X’+'</td>’);
for (row1=1; row1<=randomNum; row1++)
{
document.write(’<td>’+row1+’</td>’);
}
document.write(’</tr>’);
//—
var col1=1
for (row=1; row<=randomNum; row++)
{
document.write(’<tr>’);
//—creates index(red) column, number of rows determined by “var randomNum”—
document.write(’<td style=color:red>’+col1+++’</td>’);
//—
for (col=1; col<=randomNum; col++)
document.write(’<td>’+col*row+’</td>’);
document.write(’</tr>’);
}
document.write(’</table>’);
</script>
</table>
</body>
</html>