Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Oct 2008
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Question Having trouble creating a table using random rows and column numbers

    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:

    Code:
    <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.

  • #2
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    Sounds like a homework problem.

    Code:
    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.

  • #3
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    use DOM
    http://www.howtocreate.co.uk/tutoria...omintroduction
    That's valuable for students, as well
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •