Creating an assessment survey with pass-fail score

The Challenge

This time, we got challenged with doing something different than regular CAPI work. The challenge was to generate an assessment survey where each respondent is asked 5 questions that have correct/incorrect answers. At the end of the 5 questions, the survey needs to tell the respondent which questions he got wrong and what the correct answers were. In addition, a Pass/Fail score should be given if more than 1 answer was wrong.

The Solution

After reviewing the requirements, turns out the solution is pretty simple and consists of one expression question that does the heavy lifting (calculates the pass/fail score) and one empty question to tell the respondent the outcome:

  1. We added an expression question that calculates the pass/fail based on the correct/incorrect answers of the previous 5 questions. The correct answers are hard coded in this case but this might be enhanced in the future. Here’s the script that calculates the pass/fail score:

var numOfErrors = 0;

var MaxErrorsAllows = 1;

var retVal = 1;

if (Answer(3) != 4) {

    numOfErrors++;

}

if (Answer(5) != 2) {

    numOfErrors++;

}

if (Answer(6) != 3) {

    numOfErrors++;

}

if (Answer(7) != 2) {

    numOfErrors++;

}

if (Answer(9) != 5) {

    numOfErrors++;

}

var outcome = “”;

if (numOfErrors <= MaxErrorsAllows) {

    outcome = “passed”;

    retVal = 1;

}

else {

    outcome = “failed”;

    retVal = 0;

}

SetTextFormat(12, outcome);

return retVal;

The script simply goes over the 5 questions, and sums up the number of incorrect answers (Q3, Q5, Q6, Q7 & Q9 are the relevant questions). The script then pipes the outcome (passed/failed) to the answer of Q12 for the respondent to see.

  1. Next, we wanted to enhance the script to also show the respondent the actual incorrect questions and what the correct answer was. To do this, we enhanced the script to include the relevant text. Please note the use of the GetText() function to get the text of the question along with the AnswerText() to get the text of the correct answer. In addition, adding “\r\n” to the text makes the text skip a line when shown. We then pipe this text too to the empty question that shows the summary:

var numOfErrors = 0;

var MaxErrorsAllows = 1;

var errors = “”;

var retVal = 1;

if (Answer(3) != 4) {

    numOfErrors++;

    errors = errors+“”+QRef(3)+” was wrong.”+GetText(3)+“answer:”+AnswerText(3,4)+“”;

}

if (Answer(5) != 2) {

    numOfErrors++;

    errors = errors+“”+QRef(5)+” was wrong.”+GetText(5)+“answer:”+AnswerText(5,3)+“”;

}

if (Answer(6) != 3) {

    numOfErrors++;

    errors = errors+“”+QRef(6)+” was wrong.”+GetText(6)+“answer:”+AnswerText(6,3)+“”;

}

if (Answer(7) != 2) {

    numOfErrors++;

    errors = errors+“”+QRef(7)+” was wrong.”+GetText(7)+“answer:”+AnswerText(7,3)+“”;

}

if (Answer(9) != 5) {

    numOfErrors++;

    errors = errors+“”+QRef(9)+” was wrong.”+GetText(9)+“answer:”+AnswerText(9,5)+“”;

}

var outcome = “”;

if (numOfErrors <= MaxErrorsAllows) {

    outcome = “passed”;

    retVal = 1;

}

else {

    outcome = “failed”;

    retVal = 0;

}

SetTextFormat(12, outcome,numOfErrors,errors);

return retVal;

The yellow highlighted text shows the script enhancements made.

  1. The last step was to add the empty question which will show the respondent the summary. Here’s the text of the empty question, which has the placeholders for the text piped from the expression question:You have {0} the test. You got {1} questions wrong out of 5. List of wrong answers:{2}

Visit us at: http://www.dooblo.net

Advertisements