Currently, I am in the process of developing a page that generates random sets of questions along with their corresponding answers. Unfortunately, I am facing a challenge in matching the questions with their respective answers.
For the questions, I have created an array called 'myWords', and for the answers, another array called 'myAnswers':
//Array for Questions
var myWords = [
'Test1',
'Test2',
'Test3',
'Test4',
'Test5',
'Test6',
'Test7',
'Test8',
'Test9',
'Test10',
'Test11',
'Test12',
'Test13',
'Test14',
'Test15'
]
//Array for Answers
var myAnswers = [
'Answer1',
'Answer2',
'Answer3',
'Answer4',
'Answer5',
'Answer6',
'Answer7',
'Answer8',
'Answer9',
'Answer10',
'Answer11',
'Answer12',
'Answer13',
'Answer14',
'Answer15'
]
With this setup, I am using the following script to randomly select 10 unique questions from the 'myWords' array:
//randomly pick 10 words
while(selectWords.length < 10){
var randomWord = myWords[Math.floor(Math.random() * myWords.length)]
if(selectWords.indexOf(randomWord) > -1) continue;
selectWords[selectWords.length] = randomWord;
}
Now, the challenge I am facing is how to map each question to its corresponding answer in the 'myAnswers' array. The desired output should be presented in a table format like this:
Question 1 | Answer 1
I appreciate any help with this task. Thank you!