# How to allocate users a score based on their answers to a question or series of questions

Jump to: navigation, search

You can use logic to calculate scores based on the responses users give to questions.

Example 1

In this example, users are asked to answer No, Sometimes, Regularly or Often to questions, which are scored as 1, 2, 3 or 4 respectively. Anxiety and Depression scores are given to users based on their responses to four questions. This logic is a simple example showing how to calculate a score and show it to a user.

There are 3 pages: qp1, qp2 and qfeedback.

There are 4 numeric interactions: qp1, qp2, qp3 and qp4.

``` set depress1 to 50 set depress2 to 50 ```

```set anxiety1 to 50 set anxiety2 to 50 ```

The logic above sets the emotions to 50 so if something is not saved, you will know about it when you look at your data (this is just an extra precaution). ``` show page qp1 ```

```if (qp1.q1 = 0) set depress1 to 0 if (qp1.q1 = 1) set depress1 to 1 if (qp1.q1 = 2) set depress1 to 2 if (qp1.q1 = 3) set depress1 to 3 if (qp1.q1 = 4) set depress1 to 4 ```

```if (qp1.q2 = 0) set anxiety1 to 0 if (qp1.q2 = 1) set anxiety1 to 1 if (qp1.q2 = 2) set anxiety1 to 2 if (qp1.q2 = 3) set anxiety1 to 3 if (qp1.q2 = 4) set anxiety1 to 4 ```

```show page qp2 if (qp1.q1 = 0) set depress2 to 0 if (qp1.q1 = 1) set depress2 to 1 if (qp1.q1 = 2) set depress2 to 2 if (qp1.q1 = 3) set depress2 to 3 if (qp1.q1 = 4) set depress2 to 4 ```

```if (qp1.q2 = 0) set anxiety2 to 0 if (qp1.q2 = 1) set anxiety2 to 1 if (qp1.q2 = 2) set anxiety2 to 2 if (qp1.q2 = 3) set anxiety2 to 3 if (qp1.q2 = 4) set anxiety2 to 4 ```

```set depress_total to (sum(depress1, depress2)) set anxiety_total to (sum(anxiety1, anxiety2)) ```

```show qfeedback set qfeedback.depress_score to depress_total set qfeedback.anxiety_score to anxiety_total```

Printed variables (depress_score and anxiety_score) are used to show scores (depress_total and anxiety_total) to users.

Please click on 'Printed Variable' below to find out how to set a printed variable.

Category: