Skip to main content
Participating Frequently
February 19, 2018
Answered

Return a "Pass" or "Fail" response based on % of correct answers in quiz.

  • February 19, 2018
  • 2 replies
  • 824 views

I have a form which uses radio buttons for each series of questions. I have assigned a value of "1" to the correct response and "0" for the incorrect answers. I need to return a "Pass" or "Fail" response based on the percentage of correct answers. 80% and above = PASS, 79% and below = FAIL.

I have assigned a text box (Text1) to calculate the total of all answered questions, but I do not know how to use that value to come up with a percentage. I am thinking I need another text box (Text2) to run a custom calculation script against the value of Text1. This is where I am clueless as I do not know Javascript. Any help would be appreciated. Also, will Javascript be usable on any platform as I will no control over the end-user's device.

This topic has been closed for replies.
Correct answer George_Johnson

Sorry, that first statement should have been

var total = +getField("Text1").value;

2 replies

George_JohnsonCorrect answer
Inspiring
February 19, 2018

Sorry, that first statement should have been

var total = +getField("Text1").value;

Participating Frequently
February 19, 2018

Super George. I have marked your response as correct answer. Thanks for the timely response.

Inspiring
February 19, 2018

The custom calculation script in the Text2 field could look something like:

// Get the value of the Text1 field, as a number

var total - +getField("Text1").value;

// Set the total number of questions

var num = 20;  // Set this number to the total number of questions

// Set this field value based on the percentage correct

event.value = total / num >= 0.8 ? "Pass" : "Fail";

This is really the minimum script, but should get you started. It could be improved a number of ways, for example by only setting a Pass/Fail value when all of the questions have been answered, and something like "Incomplete" otherwise.

Participating Frequently
February 19, 2018

Thank for for the quick response, George.

I must have missed something when I copied the script as I got an error message.

I placed the script in Text2/Calculate/Custom calculation script.