0

I'm having issues randomizing the values in this array and displaying them for a specific test, using radio buttons. I want to randomize it so that the answers wouldn't appear in the same place for other questions.

let wrong_answers = [1990, 1991, 1992, 1994];

let right_answer = [1993];

let question_options = [test.right_answer].concat(test.wrong_answers);
N'Bayramberdiyev
  • 5,936
  • 7
  • 27
  • 47

1 Answers1

0

You can try using below snippet.

var arr = ['answer1', 'answer2', 'answer3', 'answer4'];

let correct_answer = ['answer3'];

let question_options = arr[Math.floor(Math.random() * arr.length)];

// verify answer! Assume user passes 'answer' value using radio button as answer

correct_answer[0] === answer ? true : 

Let me know if it is the way you wanted! I hope it'll help you.

Chirag Maniar
  • 316
  • 1
  • 5