feedback for quizzes

82 views
Skip to first unread message

Charlie Babe

unread,
Jul 16, 2021, 2:06:16 PM7/16/21
to oTree help & discussion
Hi everyone,

I am making a quiz question (multiple-choice format) and want to show the detailed answers for both right and wrong choices made by the participants.

So far I am using error_message function which can only show the feedback for the wrong choice. Is there a way that makes it show the detailed answer after the participant clicks the right choice and then the participants can proceed to the next page

I show an example below

Capture.JPG

Thank you very much!

Best.
Charlie

Chris @ oTree

unread,
Jul 16, 2021, 7:59:05 PM7/16/21
to oTree help & discussion
Make 2 pages with the same formfields:

class Quiz(Page):
    form_model = 'player'
    form_fields = ['a', 'b', 'c']

    @staticmethod
    def vars_for_template(player: Player):
        return dict(solutions=False)


class QuizSolutions(Page):
    form_model = 'player'
    form_fields = ['a', 'b', 'c']

    @staticmethod
    def vars_for_template(player: Player):
        return dict(solutions=True)

Then an includable template that's included in both page's templates like this:

{{ formfield 'a' }}
{{ if solutions }}
{{ if player.a != '42' }} <p>Your answer was incorrect. It is 42 because ....</p>
{{ endif }}

{{ formfield 'b' }}
{{ if solutions }}
{{ if player.a != '42' }} <p>Your answer was incorrect. It is 42 because ....</p>
{{ endif }}

so the formfields will be re-displayed in the second page along with solutions.
You can disable the inputs in the second page with some javascript:

<script>
for (let input of document.getElementsByTagName('input')) {
input.disabled = 'disabled';
}
</script>

but note that cheating (changing the answers on the second page) is still possible if the user knows a some javascript.

Chris @ oTree

unread,
Jul 18, 2021, 12:19:18 AM7/18/21
to oTree help & discussion
I just added an example to otree-snippets called quiz_with_feedback: 

Reply all
Reply to author
Forward
0 new messages