How build a quiz with random questions ?

Comments

quicksketch’s picture

Status: Active » Closed (fixed)

Closing after lack of activity. Sorry you were not able to receive an answer to your question.

jvieille’s picture

Version: 5.x-2.1.3 » 6.x-3.9
Status: Closed (fixed) » Active

Is this possible today?

quicksketch’s picture

Webform does not have the ability to select a random question.

quicksketch’s picture

Status: Active » Closed (fixed)
jayhaase’s picture

Just checking, because the previous responses are a bit old:

Would it be possible to build a webform quiz that could display random questions from a pool of available questions?

DanChadwick’s picture

Issue summary: View changes

Not quite.

If you wrote some custom code to generate which questions are desired, you could use conditionals to look at a hidden field and then show those questions.

Not sure if this would be possible in the 6.x-3.x and 7.x-3.x branch -- would require the webform conditionals add-on module. 7.x-4.x has conditions built in.

merylmabin’s picture

Here is my approach:

  1. Add a Hidden component with its default value set to the number of questions.
  2. In hook_form_alter, which takes $form as one of its arguments, modify the $form["submitted"] array, which contains the components ("quiz questions"):
    1. I'm going to copy this array into a new one,
    2. update the weights in this new array using rand(1, $range_limit),
    3. sort it by weight,
    4. use that hidden field to figure out how many questions to keep,
    5. and finally set $form["submitted"] to the new array.

It will be a little bit more complicated than that because there are other elements in $form["submitted"] that I'll need to keep (like "#tree" and probably the hidden field), but that's the basic idea. Feel free to let me know if there's a better way or if that just sounds like a bad way to begin with.