Illume supports complex expressions that use the ?: operator.
This operator tests an expression and returns one of two values, based on whether the expression is true or false. If the expression before the question mark is true, the expression returns the value before the colon. If it is false, it returns the value after the colon.
A simple way to remember this syntax is: Is this true ? “Yes Value” : “No Value”;
Multiple complex expressions can be included within a single calculation:
For example, this calculation which calculates the cost of an order as the number of items times the cost per item, plus a fixed rate of either $20 or $12 or $8, based on the type of shipping: {Value:NumberOfItems} * {Value:CostPerItem} + ({Value:Shipping} == “Overnight” ? 20 : 0) + ({Value:Shipping} == “3-day” ? 12 : 0) + ({Value:Shipping} == “USPS” ? 8 : 0) Assuming that the Shipping question is required and that participants can choose only one shipping option, one of the three complex expressions will be true, and the other two will be false. The true expression will add either 20 or 12 or 8 to the value of the calculation. The two false expressions will both add 0 to the calculation. Complex expressions are especially useful in calculations that must be applied differently to different participants. For example, calculations of lean body weight and blood alcohol content use different constants for men and women.
See Microsoft’s JScript Language Reference for more information about JScript.
Arithmetic Operators
+ (Plus Sign) Used for addition.
– (Minus Sign) Used for subtraction.
* (Asterisk) Used for multiplication.
/ (Forward Slash) Used for division.
Raising to a Power
math.pow({value:VARNAME}, power);
Comparison Operators
== Is equal.
!= Is not equal.
< Is less than.
> Is greater than
<= Is less than or equal to
>= Is greater than or equal to
Logical Operators
&& And
|| Or
?: If/then/else
Rscore and Score tags
While the {Value} tag yields a question’s selected response value, the {RScore} tag yields the reverse score.
To get a question’s reverse score, use the {RScore} with the question id. For example, to get the reverse score of the question SATISFACTION, use the tag {RScore:Satisfaction}.
Reverse scoring is generally used on questions that have both negative and positive items in the scale, though Illume permits reverse scoring of any items.
For questions with numeric scales, the reverse score is the score in the same position at the opposite end of the scale. The following tables illustrate reverse scores for items with numeric scales.
Score | Reverse Score |
-1 | 1 |
0 | 0 |
1 | -1 |
Score | Reverse Score |
1 | 4 |
2 | 3 |
3 | 2 |
4 | 1 |
For Check all that apply questions, the {Score} or {Value} tag gives the number of items checked. The {RScore} tag gives the number of items NOT checked.
For individual checkboxes, the {Score} tag yields a value of 1 if the item is checked and 0 if the item is not checked. The {RScore} yields the opposite values.
For non-question items (such as calculations and pre-loaded variables), the {Score} tag yields the item’s value. The {RScore} tag always yields one of the “not set” values described below.
Reverse Scoring Values for Unanswered/Unset Items
If a question has not been answered, or has no value, the {RScore} will return one of the following values, depending on the item’s data type:
- For all Numeric items that are unanswered or have no value, the {RScore} will be 0 (zero).
- For all Yes/No items that are unanswered or have no value, the {RScore} will be 0 (zero). (Note that zero is equivalent to an answer of False or No in most computer systems and applications.)
- For all Date, Time and Date/Time items that are unanswered or have no value, the {RScore} will be the current date with hours, minutes and seconds set to zero. (E.g. June 23, 2005 00:00:00.)
- For all Text types that are unanswered or have no value, the {RScore} will be an empty string (“”)– that is, a text value with a length of zero.
Calculating and Outputting Text
When text is referenced in a calculation, it is put in parenthesis, as in the examples below.
({Value:Q1}==”California”)?1:0
({Value:gender})==1)?”he”:”she”
Complex Calcs
More complex Jscript objects can be used within these calculations. A good resource for information regarding this can be found at the following URL:
http://msdn.microsoft.com/en-us/library/ye921ye4%28v=VS.80%29.aspx