mercredi 4 août 2021

How do I generate three unique items with One matching the answer to the a question?

I'm writing a quiz type app where a word in Arabic is displayed and the user has to guess the correct answer between the four displayed options.

with the code I got, I can display four random words but I have two issues.

first: I get duplicate words

Second: the _correctAnswer is not displayed every time.

Here's my code for displaying the words.

String checnkin() {
  List<String> myList = [];

  String one = Verbs().randWord();
  String two = Verbs().randWord();
  String three = Verbs().randWord();

  myList.add(one);
  myList.add(two);
  myList.add(three);
  myList.add(_correctAnswer);
  int randOption = random.nextInt(myList.length);


return myList[randOption];
}

I appreciate your help in advance.




Aucun commentaire:

Enregistrer un commentaire