I am currently working on a random number generator script that will generate three numbers. The first two numbers will be used to pick a "cell" in a "table" by referencing the row and column. Within each cell are two numbers to choose from. The third number will then determine which of the two numbers to select. I have figured out most of this but I am having problems with the last part.
My "solution" was to create twenty arrays, and within each array are twenty more arrays. Here is an example of the first array:
In the header I have the following:
Scripts to generate the first two numbers:
var randOne20 = Math.floor(Math.random()*20);
var randTwo20 = Math.floor(Math.random()*20);
Here is the first row of the 20 arrays:
var lvl1Roll1 = [[ 1,0 ],[ 1,1 ],[ 1,2 ],[ 1,3 ],[ 1,4 ],[ 1,5 ],[ 1,6 ],[ 1,7 ],[ 1,8 ],[ 1,9 ],[ 1,10 ],[ 1,11 ],[ 1,12 ],[ 1,13 ],[ 1,14 ],[ 1,15 ],[ 1,16 ],[ 1,17 ],[ 1,18 ],[ 1,19 ]];
The second row would be "lvl1Roll2" and the third would be "lvl1Roll3" etc. all the way up to "lvl1Roll20."
In the body I have the following script:
var randOne = randOne20 + 1;
document.write(window['lvl1Roll'+randOne][randTwo20]);
The randOne variable is used to select the appropriate row.
I can figure out how to select a specific cell (using the randTwo20 variable) but I have no idea how to then select the first or the second number within each cell.
Now, just to clarify, I have not listed the third random number generator code because at the moment I am just trying to figure out how to select either the first or second number within each cell. Once I figure that out I can just use an if/else statement.
Also, if I did not want to print out the number but select it as a variable how would I do that?
Thank you for any and all help!
Take care and have a great day....
ciao, john.