//random number between 1 and 26 var myRN = Math.random(); //create a variable for the random code var lower = 1; //this is the lowest 'question answer table row number' var upper = 26; //this is the highest ''question answer table row number'
NumericField1.rawValue = Math.floor(myRN*(upper - lower)) + lower; // show random number in numeric field
After generating the number you will then need to use logic to show the question and answer based on the random number. Something like:
if(NumericField1.rawValue == "3") //if the random number is 3, execute the code
//show the question and answer in row 3 in the textfields that are visible to the user.
question1TextField is the first visible text field to show the question
answer1TextField is the first visible answer field to show the answer
qaTable is the name of the hidden table storing the questions and answers
Row3.question - question is a textField on Row3 of the table holding the question
Row3.answer - answer is a textField on Row3 of the table holding the answer
Here is a start for you, there are many considerations to look at.
• If you are wanting to show 4 questions and answers with one click, it is possible that your random number might show the same number and you will have the questions and answers repeated.
• To show 4 items at once, you probably need 4 random numbers generated.
• You will need to add more logic to test if a textfield is empty or not. Meaning, in my code, i just sent the question and answer to the first visible text fields, you need to add logic so that if the first textfield is not empty, it will place the question and answer in the next text field...and so on. If you do use 4 random generators and the first field is not empty, you could then use random generator 2 etc