March 13, 2017
That’s Not Possible in Captivate! Oh, wait…maybe I can get by with a little help from JavaScript!
Comments
(7)
March 13, 2017
That’s Not Possible in Captivate! Oh, wait…maybe I can get by with a little help from JavaScript!
Joe Ganci is President of eLearningJoe, LLC, a custom learning company located outside Washington. D.C. Joe has been involved in every aspect of multimedia and learning development. He holds a degree in Computer Science and writes books and articles about eLearning. He is widely considered a guru for his expertise in eLearning development and technology, and he consults with clients worldwide, creating eLearning modules and templates, often training personnel in their use and then making himself available to assist if necessary. Of course, Joe and his team also create eLearning from start to finish, performing the proper analyses, design needs, the development of the learning and its implementation. Joe evaluates eLearning results, both for his own work and the work of others for his clients.                                                                                                                                                                                                                                                                                                                                                                                                                                          Joe is a Director with the International Association for Blended Learning (IABL), a nonprofit international organization whose goal is to promote the use of the best form of learning for each component of a learning curriculum across all industries and academia. This year he organized and ran the 24-Hour Conference IABL Online Conference.                                                                                                                                                                                                                                                                                                                                        Joe is also a frequent teacher and presenter online and at industry conferences and client sites (during times without a pandemic!) , especially on the subject of eLearning design and development tools. His tool reviews appear each month in Learning Solutions Magazine and he is the recipient of several awards and many letters of recommendation for his work in eLearning, including a Lifetime Achievement Award way back in 1999 and the second ever eLearning GuildMaster Award in 2013. His mission is to improve the quality of eLearning with practical approaches that work.
Guide 5 posts
Followers: 30 people
(7)

Case Study: I Get By With a Little Help from JavaScript… with Amazing Results

A while ago, I was asked if I could put together a set of addition problems for children in Captivate. However, the requirements were a bit daunting:

  1. The learner could continue solving problems, one after the other, all day. In essence, the number of problems to solve would need to be in the hundreds.

    Thoughts: Wouldn’t that mean creating hundreds of Captivate slides? Should they be quiz slides or content slides?

  2. The learner should be able to choose the lowest number and the highest number to add. For instance, the learner could choose to solve only one-digit numbers or to solve numbers that range between 134 and 189.

    Thoughts: Oh-oh. Now I’m looking at possibly thousands of slides, and choosing to jump to a certain section of slides depending on what range of numbers the learner chooses. But, really, I could maybe set up different quiz pools in which one pool is single digits, another is double-digit numbers, etc., and then randomly select from the proper pools.

    Three problems with this:
    1) I’d still have to create thousands of questions slides for those pools to work right.
    2) Every question in every pool must be part of the published files because questions are chosen randomly at run-time, so that’s going to make for a very big project.
    3) There’s still no way I could guarantee that I would show only numbers between an arbitrary range the learner chooses, such as only numbers between 43 and 65.

  3. The learner should be able to change the range at any time.

    Thoughts: Know what? I’m sorry, this isn’t going to work. Unless…wait a minute…

I started to think about how JavaScript could help. The next thing I knew, I had created:

  1. One slide in Captivate capable of presenting an infinite number of sum problems, in which…
  2. …the learner can choose the range, any range, at any time.

Yes! A little bit of JavaScript here will go a long way to making this a simple project.

How does this work?

First, I put three text entry boxes on the stage as you can see in the image. They are nothing special. The only thing I did to them was to:

  1. Set each to accept numbers only so that learners wouldn’t accidentally input other characters.1
  2. Set each text entry box to a variable name of my choosing:
    _rangeButton, _rangeTop, _learnerAnswer

Below you can see both the playback and the source stages. It’s important to run this off a web server, and not locally.

  1. Try the HTML5 version: http://www.elearningjoe.com/tools/captivate/jscpmath/index.html
  2. Try the Flash version:   http://www.elearningjoe.com/tools/captivate/jscpmath/CP-JS_MathProblems.htm

MORE NOTES ARE BELOW THE IMAGES.

2

3

Each of the two buttons executes JavaScript in Captivate.

Here is the JavaScript I wrote for Show Me a Problem. I’ve added line numbers here for easier referencing.

  1. var lowNum = window.cpAPIInterface.getVariableValue(‘_rangeBottom’);
  2. var highNum = window.cpAPIInterface.getVariableValue(‘_rangeTop’);
  3. var rand1 = Math.floor(Math.random() * (highNum – lowNum)) + lowNum;
  4. var rand2 = Math.floor(Math.random() * (highNum – lowNum)) + lowNum;
  5. cpAPIInterface.setVariableValue(‘_rand1’, rand1);
  6. cpAPIInterface.setVariableValue(‘_rand2’, rand2);

Lines 1 and 2 grab the values for the variables in Captivate _rangeBottom and _rangeTop, which start by default at 1 and 10 but that the learner can change at any time. It places them into two new declared I declared called lowNum and highNum.

Lines 3 and 4 each calculate a random integer within the defined range and puts them into the variables I declared called rand1 and rand2.

Lines 5 and 6 then put the random integer values into the Captivate variables called ­_rand1 and _rand2.

Pretty simple, right?

Here is the JavaScript for Am I Right?

  1. var rand1 = window.cpAPIInterface.getVariableValue(‘_rand1’);
  2. var rand2 = window.cpAPIInterface.getVariableValue(‘_rand2’);
  3. var sum = window.cpAPIInterface.getVariableValue(‘_learnerAnswer’);
  4. var sumFeedback;
  5. var corrSum = rand1 + rand2;
  6. if (sum == corrSum ) { sumFeedback = ‘That is correct!’; }
  7. else { sumFeedback = ‘Sorry, the answer is ‘ + corrSum + ‘.’; }
  8. cpAPIInterface.setVariableValue(‘_sumFeedback’, sumFeedback);

The first three lines grab the values for the variables in Captivate _rand1, _rand2 and _learnerAnswer and I place them into three variables I declare called rand1, rand2 and sum.

You might be wondering why we have to load the random values from Captivate. Wouldn’t it remember the values for the JavaScript variables rand1 and rand2 from the script we attached to Show Me a Problem? Didn’t I declare the JavaScript variables rand1 and rand2 in that script?

Yes, that is true, but there’s no guarantee that the learner will click the Show Me a Problem button first, so that script may not execute before the learner attempts to answer the first problem.

In fact, I set the starting values for the Captivate variables I created, _rangeBottom and _rangeTop, to 1 and 10 so that those two fields won’t start out empty. This means the learner could attempt to answer the problem 1 + 10 before entering new values and pressing Show Me a Problem. Therefore, I must declare them and load their values in this script in case the learner’s first step is to answer the problem on the screen, answering 1 + 10.

Line 4 declares the variable for our feedback.

Line 5 declares the variable corrSum and immediately sets it to be the addition of my two random numbers.

Lines 6 and 7 then checks whether the learner’s answer (sum) is equal to the value we just calculated (corrSum). If so, I set the feedback variable to That is correct! If not, we set it to Sorry, the answer is followed by the correct answer and a period.

Finally, Line 8 puts the value of our feedback variable into the Captivate variable _sumFeedback.

Let me know if you have any questions.

 

7 Comments
2017-07-12 21:48:27
2017-07-12 21:48:27

This looks cool. I am really an absolute beginner but I think this is the stuff I need to learn in my 10 weeks of from university!

Like
(1)
2017-04-07 13:14:53
2017-04-07 13:14:53

This is pretty neat, I’m gonna try too!

Like
(1)
2017-03-15 03:33:49
2017-03-15 03:33:49

Thanks for posting Joe. I’m expanding my knowledge on how to use Javascript in Captivate, very powerful stuff! Thanks again

Like
(1)
2017-03-14 11:27:06
2017-03-14 11:27:06

A while ago I published two blog posts explaining a similar situation, which have an interactive captivate tutorial included:
http://blog.lilybiri.com/playing-with-numbers-part-1
http://blog.lilybiri.com/playing-with-numbers-part-2

The reason I couldn’t publish it here, is that you cannot include interactive tutorials in this portal.

Like
(1)
(1)
>
Lieve Weymeis
's comment
2017-03-14 17:19:14
2017-03-14 17:19:14
>
Lieve Weymeis
's comment

Very nice, Lieve! Great minds think alike. I have so many ideas for how to apply JavaScript and I’m going to post some other ones as soon as I can.

Like
(1)
2017-03-14 08:36:57
2017-03-14 08:36:57

If you find this useful, let me know how you’ve applied this. I’d love to know!

Like
(2)
(1)
>
Anonymous
's comment
2017-03-15 20:38:48
2017-03-15 20:38:48
>
Anonymous
's comment

Wow. Looks like like I’ll have to learn javascript. Seems it’s used everywhere anyway.

Like
(1)
Add Comment