Rock, Paper, Scissors! – Randomizing Content with Javascript

Tool: Adobe Captivate (2017 Release)
Feature: Using Javascript to generate random answers.

This project came as an idea from this E-Learning Heroes Challenge: using Javascript to randomly generate words in Storyline. I decided to take on the challenge and create a game of Rock, Paper, Scissors where the user plays against the computer by thinking of a shape first then challenging the machine with the click of a button. I used Adobe Captivate instead, since I wanted to get more familiar with the use of Javascript with that particular authoring tool.

This solution is very interesting for any type of activity that requires the learner to generate random answers, such as  random words for a writing exercise, or to build flash cards or even to learn a foreign language.


Here’s how I created the Javascript code:

  1. First, I created a variable called “RandomWord” and placed somewhere in the slide using the tags $$RandomWord$$.
  2. Then I create the following Javascript script:

var words = [“Rock”, “Paper”, “Scissors”];
var word = words[Math.floor(Math.random() * words.length)];
window.cpAPIInterface.setVariableValue(“RandomWord”, word);

The first line of the code is where you input the content you want to randomize. Change the third and fourth line to align with the variable name you created  previously (remember, mine is RandomWord)

3. Once you created your variable and your script, create an Advanced Action that to execute the Javascript. In my example, the user clicks the Play button, which in turn initiates the Advanced Action that executes the Javascript.

Click here to see how I created my first Adobe Captivate game using Javascript. I hope this inspired you to find a skill you are trying to stretch a little further and begin conquering it!