...

View Full Version : Having trouble creating a table using random rows and column numbers



omega_lonestar
10-16-2008, 02:10 PM
I'm helping a friend that is interested in writing a script where you generate two random numbers for two variables (one variable will be for the rows and the other will be for the column) in the range from 1 to 10. I want to make sure that each of the cells have the word "cool" in it. It has to have a function where it prints out the table. So far, I have this as my coding:



<html>
<head>
</head>

<body>

<table border="2">
<script>

var m=Math.round(1 + Math.random()* 10);
var n=Math.round(1 + Math.random()* 10);


for (i=0;i<=m;i++)
{
function f(n)
{
document.write(n);
}
}

for(i=0;i<=n;i++)
{
f("<tr><td>Cool</td></tr>");
}

</script>

</body>
</html>


I managed to get one column to display but it doesn't seem to expand. Every time I refresh it just changes rows for that one column only.
Anyone have any ideas how I can approach this? Thanks.

tomws
10-16-2008, 03:15 PM
Sounds like a homework problem.


f("<tr><td>Cool</td></tr>");


You want more than one column, yes? Then code in more than one column. You just have one cell per row in that code.

Kor
10-16-2008, 03:17 PM
use DOM
http://www.howtocreate.co.uk/tutorials/javascript/domintroduction
That's valuable for students, as well :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum