##### Page tree
Go to start of banner

# Coding

The code portion of a question is used to define solutions to the different question parts, but it can also be used to perform calculations and initialize variables that can be used in the TeX portion. Each question part in the question body must define and initialize an answer in the code portion. The Quest Editor requires either Javascript or C in the code portion of questions.

No TeX is allowed in the code portion of a TeX question, especially in the definition of answer units. To avoid errors, spell out units that require more complicated symbols, like degrees, percents, etc.

## Javascript (JS)

A Javascript question will be defined like a Javascript function: function js_answer() { }. All code you write in this section must be contained in the function brackets. When using Javascript in the code portion of a TeX question, take special notice of semicolons and matching opening and closing braces {}. Like any Javascript code, each statement must end in a semicolon and all functions, loops, and conditional statement blocks must begin and end in curly braces. If you want to learn a little more about Javascript in general, try this link.

For more details about using Javascript, use question ID 169286 as a template to create a reference question in your bank.

Javascript (JS) is one of the coding languages used in the code box for Tex & (C/JS) or html+JS. If you're unfamiliar with this language here are a few primers:

## C

When writing the coding portion of the question in C, begin with "void answer(void) { }" and insert all code between the curly braces. Any variables you want to reference in the TeX portion of the problem must be defined as follows: /* global (insert type) (insert name) */ (without the parentheses). You can also specify units you want to be displayed after the variable by typing "u={type}" where type can be m, kg, etc. The rest of the problem can then be coded like a normal C program.

## Using variables (@)

Variables that have been declared and given a value in the code portion (see below) can be referenced in the question body with a preceding "@" symbol. For instance, if you calculated the variable k in the code portion and wanted to display the square root of k in an equation in the question body, you would simply type $\sqrt{@k}$. If k has been given a value, the editor will grab this value from the code portion and display it in the question body. Make sure you have initialized the variable in the code portion or you will receive an error message, and the question will not work.