Easily set up restrictions on when an Action can be fired based on variables

When you set up an Action, the panel includes a field, Conditions.

You can use this field to set conditions on when the action will happen, based on the value of a variable.

You use JavaScript Comparison Operators to set the conditions such as:

  • ==   equal to
  • === equal value and equal type

JavaScript Conditions

JavaScript Condition Operators
OperatorDescription

==

equal to
!=not equal
>greater than
<less than
>=greater than or equal to
<=less than or equal to
&&AND operator, connects two conditions together and both must be met
||OR operator, connects two conditions together and either condition may be met
( )Use parentheses to control how multiple conditions are connected. Items inside a set of parentheses are resolved first and then compared to conditions outside the parentheses

 

Example Based on Numeric Variables

In your course, learners have been earning points, and the value has been stored as a numeric variable, “Scoring”.

At the end of the course, you want to show text feedback for two possibilities:

  • If the score is less than 10
  • If the score is equal to or greater than 10

On the last page, you could set up a page action to show each feedback text element on page load. For the first possibility, add a condition, {{Scoring}} < 10.

 

To start, you add the variable to the conditions field:

  1. Right-click in the Conditions field

  2. In the search dialogue type, Scoring

  3. Select the variable, Scoring

  4. The variable string is now shown in the Conditions field

  5. Type < 10 

 

Now repeat this sequence, but change step 5 to  >= 10 for the positive message.

Example Based on Text Variables

In this example, you have a text input box added to a page tied to a custom variable, “TypedResponse”. So what the learner types in the text input box is saved as the text string value for the variable “TypedResponse”.

 

You are expecting the learner to type in a specific text string. You'd like to show feedback based on what the learner types, providing feedback for correct and incorrect entries.

 

In this example, the learner was asked what the largest land animal in existence today is. The correct answer is "elephant". 

 

On the question page, you want to show text feedback for two possibilities:

  • If the answer is elephant 
  • If the answer is not elephant

For the first possibility, add a condition, {{TypedResponse}} == "elephant".

NOTE: Single or double quotes can be used, but we recommend you always use one or the other in individual condition statements.

 

Add the action to show the correct answer, and then add the variable to the conditions field:

  1. Right-click in the Conditions field
  2. In the search dialogue type, TypedResponse
  3. Select the variable, TypedResponse
  4. The variable string is now shown in the Conditions field
  5. Type == "elephant"
  6. At this point, you could stop, but if you want to account for variations in what the learner typed, your updated statement would be:
    1. {{TypedResponse}} == "elephant" || {{TypedResponse}} == "Elephant" || {{TypedResponse}} == "ELEPHANT"


This condition will look at what the user typed and will show the correct feedback if the typed answer matches any of the three strings. Yes, matches are case sensitive. The || symbol means "or".


For the incorrect answer, add the action to show the incorrect answer, and then add the variable to the conditions field:

  1. Right-click in the Conditions field
  2. In the search dialogue type, TypedResponse
  3. Select the variable, TypedResponse
  4. The variable string is now shown in the Conditions field
  5. Type != "elephant"
  6. At this point, you could stop, but if you want to account for variations in what the learner typed, your updated statement would be:
    1. {{TypedResponse}} != "elephant" && {{TypedResponse}} != "Elephant" && {{TypedResponse}} != "ELEPHANT" 


This condition will look at what the user typed and will show the incorrect feedback if the typed answer matches any of the three strings. The && symbol means "and". In this case, we want to make sure that the answer is not equal to all three strings.

NOTE: If your use case is simply a fill in the blank question, our built-in fill in the blank practice/test question will provide this type of functionality automatically. 

Providing Feedback for a Range of Scores

Your project allows the learner to collect points for different actions, and the points are totaled as a custom variable, “Score”.

 

On the final page of the project, you want to provide feedback for three different ranges of scores:

  • Low score feedback for less than 10 points
  • Medium score feedback for 11 to 25 points
  • Excellent score feedback for 26 points or more

 

The feedback could be a text element, a graphic, or any combination of elements – whatever your creativity inspires!

 

Set Up

On the final page of the project, you can set up three show actions, one each to show the Low, Medium, and Excellent score feedback, based on the trigger Current Page is Loaded.

 

Each Show action uses conditions to determine whether the action should be fired or not.

 

For the Low score feedback, you would add this in the Conditions field so the action only fires if the Score variable is equal to or less than 10:

  • {{Score}} <= 10

 

For the Excellent score feedback, you would add this in the Conditions field so the action only fires if the Score variable is equal to or greater than 25:

  • {{Score}}  >= 26

 

For the medium score feedback, you will need two conditions:

  1. One to check that the variable score is greater than or equal to 11
  2. One to check that the variable score is less than or equal to 25.

To combine these together, you use two ampersands (&&), which tells the condition that both conditions must be met before the action can be triggered.

Here’s what this looks like in the Conditions field:

{{Score}}  >= 11 && {{Score}}  <= 25

Multiple Conditions: Using Conditions with Standard Comparison Triggers

With the conditions field you can add multiple conditions and criteria for your trigger and also combine it with standard trigger conditions. How you combine them will determine how the conditions are interpreted. Let's review a few examples.

 

Standard Triggers Combined with Conditions

In this example, you have an action to show some feedback, but only want the feedback to show if the learner gained 10 or more Gold Points and they completed all the learning content. There are several ways to accomplish this. One is to use a standard trigger of when a variable changes, and then combine it with an additional condition. 

 

In this case, the condition will be {{sys.learner.completion}} == 100.

 

This works because when you use a standard trigger and then add a condition, the standard trigger and set of condition statements you add are connected by an AND operator. 

 

What About Triggering if Either Condition is True?

For this use case, change the trigger to be set to: on page load. You need to make this change, as you cannot override the default AND operator that connects the standard trigger and condition set.

 

In the conditions field, add:

  • {{Gold Points}} >= 10 || {sys.learner.completion}} = 100

Multiple Conditions: Using Paranthesis

As you develop more complex conditions, using carefully placed parentheses will be your friend. If you remember your lessons on order of operations from math classes, then you will be set. If not, don't worry, the level of complexity required here is quite small! 

 

Use Case: Either of two conditions must be met, but in addition, a third condition must also be met

The use of parentheses enables you to tell the condition statement to analyze certain conditions before others. In this situation, there are two overall conditions that both must be met, and within one of these conditions, a match of either of the two conditions can be met to meet the overall condition.

 

Example

You want to provide congratulatory feedback if the learner received 10 Gold Points or they completed all the learning in the course, sys.learner.completion, but only do so if the learner is also part of the User Group - Beginners. To operationalize this condition you would use the following condition:

  • ({{Gold Points}} >= 10 || {{sys.learner.completion}} = 100) && {{User Goup}} == "Beginners"

In this case, it will first evaluate the Gold Points and Learner Completion and if either is true that part of the condition will be met. Then it look to User Group and if it is Beginners then both conditions will be me and the action of showing the feedback will fire.

Additional Resources

W3Schools has some excellent resources.

To learn more about JavaScript Conditions notation access: W3Schools JavaScript Comparisons.

  0     0

Similar Projects

Questions  ( 0 )