Expressions can be used in action parameters to calculate parameter values. CourseLab variables and object properties can be used as expression arguments along with numbers and strings. When action is launched, every expression in action parameters is evaluated and replaced with expression value.
Boolean expression is the type of expressions that has boolean true or false as a result of evaluation. This type of expression is generally used in IF action to define condition statement. Example of boolean expression:
#var1==#var2+10
Note, that if you define incorrect expression, it may cause the error in module. Please double check expression syntax to avoid problems.
Operators allowed for building expressions:
Operator Description Arithmetic/String + Addition of numbers or concatenation of strings - Subtraction or negation (numbers only) * Multiplication (numbers only) / Division (numbers only) Boolean ! NOT - unary Boolean negation - if operand evaluates to true then the result evaluates to false and vice versa. && AND - if both operands evaluate to true then the result evaluates to true, otherwise - false. || OR - if either or both operands evaluate to true then the result evaluates to true, otherwise - false. Comparison != Not equal (usually works fine, but may depend on automatic data type conversion *) == Equal (usually works fine, but may depend on automatic data type conversion *) > Greater than >= Greater than or equal < Less than <= Less than or equal
* Data type conversion: numbers and symbols of numbers are different types of data, i.e. in general, for example, 34 should not be equal to "34" (first is number, second is string). But JavaScript programming language (which is used in CourseLab runtime) has automatic data type conversion feature, i.e. 34 may be equal to "34" in conditional statement. Please be aware of this feature.
Data types allowed for building expressions:
Data type Description NUMBER [0...9] - any sequence of these characters BOOLEAN true | false - predefined dictionary values STRING Any character sequence enclosed in quotes ("" or ''). Using of " and ' inside the string is forbidden - if you need these characters to be included in string - use backslash to mask them (i.e. \" will mean single " inside the string). VARIABLE CourseLab run-time variable value (i.e. # sign followed by variable name). Name can consist of alphanumeric symbols (a-z, A-Z, 0-9) and _ (underscore). Name must not contain whitespaces and other special symbols. IDENTIFIER Used for inserting object properties in expression. Syntax for object property is: $object_identifier.object_ property, where object_identifier and object_property are of IDENTIFIER data type. Name can consist of alphanumeric symbols (a-z, A-Z, 0-9) and _ (underscore). Name must not contain whitespaces and other special symbols.
Math functions allowed for building expressions:
Function Description Math.random() returns random number greater than 0 and less than 1 Math.PI returns PI value Math.sin( x) returns sine of x Math.cos( x) returns cosine of x
Expression Description #var1<=#var2+10 Simple boolean expression for IF action ((#var1>5) && (#var2>10)) || #var3=='cancel' Complex boolean expression for IF action #var1*#var2/100 Numeric expression for defining action parameter numeric value (arythmentic) #var1+" - correct answer" String expression for defining action parameter string value (concatenating strings)