Results 1 to 3 of 3
  1. #1
    melissa1163 is offline Member
    Join Date
    Feb 2011
    Posts
    1
    Rep Power
    0

    Default Random Number and Table

    so im just getting started:

    I am trying to get a random number generator to generate either a 1,2,3 and then depending on the number put the word "car" into that cell of a table. I then ideally would want the other two empty cells to automatically be filled with a term such as "empty"

    this is what i have so far...

    <head>
    </head>
    <body>

    <table border="5">
    <tr>
    <td><script language="Javascript">
    <!--
    door= new Array
    door[1]="car"
    door[2]="car"
    door[3]="car"


    var rand_no = Math.floor((4-1)*Math.random()) + 1;


    document.write(door[rand_no]);
    -->
    </script></td>
    <td>row 1, cell 2</td>
    <td>row 1, cell 3</td>
    </tr>
    <tr>
    <td>door1</td>
    <td>door2</td>
    <td>door3</td>
    </tr>
    </table>

    <script language="Javascript">
    <!--
    door= new Array
    door[1]="car"
    door[2]="car"
    door[3]="car"


    var rand_no = Math.floor((4-1)*Math.random()) + 1;


    document.write(door[rand_no]);
    -->
    </script>

    </body></html>

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,784
    Rep Power
    7

    Default

    This is a Java forum and not a JavaScript forum

  3. #3
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,784
    Rep Power
    7

    Default

    Java Code:
    var rand_no = Math.floor(([B]4-1[/B])*Math.random()) + 1;
    If you are going to hard code values, why not just hard code a 3?

Similar Threads

  1. Random Mult. Table
    By teelnaw in forum New To Java
    Replies: 9
    Last Post: 10-30-2010, 12:17 AM
  2. Random number generater
    By kickflipper1087 in forum New To Java
    Replies: 6
    Last Post: 10-21-2008, 10:19 PM
  3. Random number help
    By jgonzalez14 in forum New To Java
    Replies: 5
    Last Post: 09-16-2008, 09:13 AM
  4. Random number
    By jithan in forum Advanced Java
    Replies: 1
    Last Post: 06-13-2008, 01:42 PM
  5. Generate a random number
    By romina in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 05:23 AM

Posting Permissions

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