Auto-evaluation by Javascript function
Develop your own evaluator javascript function
It is possible to create a personalized JavaScript function that can automatically assess the provided response for an input question associated with Text-field, Text area, or Numeric input types and generate a percentage score as a result.
Creating a custom Javascript function
Your organization can develop and save customized JavaScript functions internally. To access these functions, please follow the steps outlined below:
- Select "Organization" from the primary navigation menu located on the left-hand side of the Testinvite application.
- Select Snippets from the presented options.
- Select Functions from the presented snippet options.
A catalog of previously established custom functions will appear. To generate a new function, click on the red plus icon located in the lower-right corner of the page. A new form will appear, accompanied by a code editor.
- Provide a title for your custom function.
- Provide a description for your custom function.
- Compose a personalized code for the function.

Composing the function code
The function must be designated as anonymous, and it should permit only one parameter, which can be named "data." The question's given answer will be transferred to your function via the "data" parameter, allowing you to analyze its contents, create a customized algorithm, and return an object with a single property called "score." The value of the "score" property should be a numeric value between -1 and 1.
Example function code
function anonymous(data) {
if (!data.response) return { score: 0 };
try {
let answer = parseInt(data.response)
if (answer > 1000) return { score: 1 }
else if (answer > 500) return { score: 0.5 }
else return { score: 0 }
}
catch (err) {
return { score: -1 }
}
}
The "data" parameter is anticipated to have a "response" property inside it, which may either contain an "undefined" value or a string value.
Emulating the execution of the function proving the data parameter
By selecting the "Emulator" button situated at the lower-right corner of the code editor, you can experiment with your function by crafting a data parameter in JSON format.
- Create a JSON object with one property called "response" and allocate it a string value.
- Click on the Apply button.
- Observe the output area. The score property must be a number between -1 and 1.

Linking your personalized function with an input question as the automated evaluator.
If the input type is Text-field, Text area, or Numeric, your function can be connected with the input question as an automated evaluator.

Previewing your question and the operation of auto-scoring
Once you have linked your customized function with the input question, you may preview the question, provide a sample response, and select the Previewing score button located at the lower-right corner to test how your response is being automatically evaluated by your personalized JavaScript function.

- Side effects
- Dimensions
- Scoring and point system
- Fill in the blank questions
- Content groups
- Matching and sorting questions
- Creating a rubric
- Importing input questions
- Take a picture questions
- Interview questions
- Speaking questions
- Coding questions
- File upload questions
- Fill-in-a-table question
- Writing question
- Auto-evaluation rules
- Validation of text and numeric inputs
- Numerical entry question
- Text entry questions
- Input questions
- Alignment of choices
- Dropdown list
- Importing in bulk
- Quick paste tool
- Scoring
- Multiple choice questions
- Extra features
- Adding hint
- Adding feedback
- Adding a sidebar
- Attaching a file
- Adding video clip
- Adding audio clip
- Adding image
- Formatting the question text
- Composing a test question
- Creating test questions