Question T12510
Visible to All Users

Assigning Values/Points to a questions and summing the Score at the End

created 2 years ago

Hello,

We need to be able to assign points or values to the answers of questions on the Forms. The example below show (+2 points, etc.) is this a value that can be assigned under the data info? so that it doesn't show on a survey? we'd like to hide the score of the survey from the user taking it, but need to see the score when reviewing the results on our end.


Example:

  1. Question 1
    [ X ] Answer 1 (+2 points)
    [ ] Answer 2 (+1 point)
    [ ] Answer 3 (0 points)
    [ ] Answer 4 (-1 point)
    [ ] Answer 5 (-2 points)

  2. Question 2
    [ ] Answer 1 (+2 points)
    [ X ] Answer 2 (+1 point)
    [ ] Answer 3 (0 points)
    [ ] Answer 4 (-1 point)
    [ ] Answer 5 (-2 points)

  3. Question 3
    [ ] Answer 1 (+2 points)
    [ ] Answer 2 (+1 point)
    [ ] Answer 3 (0 points)
    [ X ] Answer 4 (-1 point)
    [ ] Answer 5 (-2 points)

Survey Score: 2


Thank you

Answers approved by surveyjs Support

created 2 years ago (modified 2 years ago)

Hello,
Yes, it is possible to assign point values to form question options. Please refer to the following demo: Scored Survey.

To assign point values to question options, implement a custom score property for question options. The score property will be serialized and included in the survey JSON schema.

  • Add the score property to the ItemValue class as shown below. This class describes a choice in any select question type.
JavaScript
import { Serializer } from "survey-core"; Serializer.addProperty("itemvalue", { name: "score:number" });

For more information on how to add custom properties to a survey element, refer to the following help topic: Add Custom Properties to the Property Grid.

  • Assign scores to choice options.
    Set the score property of each choice option to a number.

  • Calculate the total score.
    Iterate over all choices, to find the selected answers and sum up their scores (see the calculateTotalScore helper function). For simpler iteration, you can call the getPlainData(options) method and get survey results as a flat data array. In addition, you can calculate the maximum possible score (see the calculateMaxScore helper function). Initiate these calculations within the onComplete event handler as shown in this demo.

  • [Optionally] Display different Complete pages based on earned points.
    Use the completeHtmlOnCondition array to specify different HTML markup for the Complete page. Each object in this array should include the expression and html properties. When the expression evaluates to true, the survey applies the corresponding markup. For more information on expressions, refer to the Expressions help topic. To use the total and maximum scores in the expression or HTML markup, add them to survey results by calling the setValue(name, value) method.

Let me know if you have any questions or require further assistance.