How to calculate outcome of quiz


#1

In my app, i want to add a short quiz/test. There are six questions and each one can be answered by clicking 1-5 on a scale (from ‘completely disagree’ to ‘completely agree’). I made five circular buttons to represent the scale. The outcome score can be calculated as follows:

'Add the responses varying from 1-5 for all six items giving a range from 6-30. Divide the total
sum by the total number of questions answered. ’

How do I add this formula to my quiz so that afterwards the correct score is shown?


#2

There are (at least) a few different ways you can do this …in general, regardless of Axure version.

  • Use global variables. I’ll use some example global variable names here:
    • varItems : stores an identifier (ID) for each answered item, such as a number, letter, or label.
    • varCount : stores number of answered items.
    • varSum : stores total of answered item values.
    • varAverage : stores varSum / varCount. (optional; can be calculated as needed, e.g., upon a button press.)
    • Details:
      • It is best to store the ID and a “delimiter” --some char that separates each ID, like a comma, period, semicolon, etc., especially if your ID is numbers–to differentiate between “1”, “10”, “21” etc. Let’s say your question item ID is a letter, so when user answers the first item, the value of varItems would be “A,” and then after they answer the second item, varItems would be “A,B,” and so forth. (But with letters and fewer than 26 items (for English alphabet) delimiters not required.)
      • I recommend naming each radio button with its value, e.g., “1” , “2” , “3” etc. so you can refer to it when calculating the sum.
      • Because you have 5 radio buttons per item, and only one can be selected at a time, you’ll want to assign a unique Selection Group or Radio Group for each item’s set of radio buttons, to automatically enforce this rule.
      • You’ll need to keep track of answered items and not individual radio button clicks. For example, if a user first selects ‘4’ for item A, then varItems can be updated to include “A,”. But if the user then changes their mind and selects ‘3’ for item A, varItems does not need to be updated. (Likewise, the sum would not update to 7 but rather change from 4 to 3.)
      • So, if you are using a true Radio Button widget, when it gets clicked it gets selected (and the way to unselect it is to select another radio button in its Radio Group, or have another widget/action specifically set it to unselected.) If you’ve manually created a kind of custom radio button–e.g., with an Ellipse widget–you’ll want to assign the Click or Tap event with "Set selected of This to “true”. Each radio button’s Selected event should test if its item ID exists in varItems–meaning, “has this item been answered already?” and update varItems if needed, and always add its value–using its name–to varSum. When unselected always decrement its value from varSum. …Something like,

Selected
If value of varItems does not contain “A,”
Set value of varItems to “[[varItems]]A,”
Set value of varCount to [[varCount + 1]]
If true
Set value of varSum to [[varSum + This.name]]
Unselected
Set value of varSum to [[varSum - This.name]]

  • If you want a running average to be calculated, you can also add an action to update varAverage using the expression, [[varSum / varCount]]
  • If you don’t need a running average, you can assign this expression to a button’s Click or Tap event.

  • Or, you can use text values of widgets (shown or hidden) in place of global variables. This creates a set of “page local variables”.
    • You can have one hidden widget for the count of answered items, one hidden widget for the sum of answered question values, and one widget (hidden or not) for the average.
    • Each question item can be a group or dynamic panel (dp) containing the question label, 5 radio buttons, and a hidden “score” widget used for that item’s score. (I recommend keeping it unhidden while you are coding/testing/debugging your prototype, then hiding once everything works correctly.)
      • By default the item Score widget’s text value is blank or 0.
      • When a radio button is selected, it
        • Sets the Score widget’s text value to the value of this radio button.
        • Sets the text value of the item’s Count widget to 1.
        • Adds the Score widget’s value to the Sum widget.
        • Sets the text of the Average widget to the value of Sum divided by the value of Count.
      • When a radio button is unselected, it
        • Subtracts this radio button’s value from the Sum widget.

  • Or, you can use a repeater for the list of question items and calculate the sum and average using conditional cases in the repeater’s Item Loaded event.
    • The repeater’s datasheet can have columns for (at least)
      • Question
      • Answer
    • When a radio button is clicked it can update “This” row in the repeater (or Edit Row Data action for RP10), setting the Answer column to the radio button’s value. For example,
      Update Rows
      (Repeater) set Answer to “[[This.name]]” for This
    • In the repeater’s Item Loaded event, include these conditional cases:
      • If true
        Set Text
        QuestionLabel to “[[Item.Question]]”
      • If [[Item.isFirst]] equals “true”
        Set value of varCount to 0
        Set value of varSum to 0
      • If value of [[Item.Answer]] is greater than 0
        Set value of varCount to [[varCount + 1]]
        Set value of varSum to [[VarSum + Item.Answer]]
      • If [[Item.isLast]] equals “true”
        Set value of varAverage to [[(varSum / varCount).toFixed(1)]]
        (…for 1-digit precision, which is appropriate for max of 6 items; e.g. “4.2”)
      • If value of [[Item.Answer]] equals “1”
        Set selected of 1 to “true”
        (…where the first radio button is named “1”)
      • Else If value of [[Item.Answer]] equals “2”
        Set selected of 2 to “true”
      • Else If value of [[Item.Answer]] equals “3”
        Set selected of 3 to “true”
      • Else If value of [[Item.Answer]] equals “4”
        Set selected of 4 to “true”
      • Else If value of [[Item.Answer]] equals “5”
        Set selected of 5 to “true”