Calculator to Populate Dates

Feb 04, 2016

Hi everyone--

I'm looking for a way for Storyline to generate five dates based on a "final" date submitted by the learner (learner submits any date they want). Each of the five dates calculates 30-10 weeks backwards from the final date.

For example, if the learner types August 1 as the final date, Storyline would calculate the following dates: Jan 4, March 28, April 25, etc. 

Any idea how to do this without needing coding? Thanks!

9 Replies
Steve Gannon

Hi Sarah,

I think the attached sample file accomplishes what you want. It uses Javascript to subtract the required number of days from the date the user enters. (Take a look at the code within the Execute Javascript trigger.)

For use in an actual project, you will probably want to add some error checking to caution the user if she enters a number out of range (e.g., as entering '13' for the month or '32' for the day). The script I drafted would require fewer variables and would be more efficient if I used a loop and more arrays but I wanted to make it relatively easy to follow in case you're new to Javascript.

A few caveats about using Javascript with Storyline:

1. You have to publish the project to see the results (it won't work in preview).

2. When passing variables back and forth between Javascript and Storyline, the exact same spelling of that variable must be used in both. In other words, you can't create a variable in Javascript and send that variable value to Storyline if the corresponding variable has not already been created in Storyline.

3. Javascript will not work with the Articulate Mobile Player app (but it will work with Flash and HTML5 output).

4. You may have to post the published output to a web server and run it from there because sometimes browser security settings restrict Javascript from running on a local drive.

Hope that gets you started!

Zsolt Olah

Steve, 

Nice write up!

As for #2, 

"When passing variables back and forth between Javascript and Storyline, the exact same spelling of that variable must be used in both. In other words, you can't create a variable in Javascript and send that variable value to Storyline if the corresponding variable has not already been created in Storyline."

Just for clarification, in JS you can create a variable:

var myVariable = 10;

Then send the value to Storyline to set a variable, let's say Points, for example:

var player = GetPlayer();

player.SetVar("Points",myVariable);

This would set the Storyline variable, "Points" to 10.

 

 

Steve Gannon

You're right, of course, Zsolt. I could have communicated that better. What I was trying to get across to Sarah was that the variable that you're going to set using Javascript and pass back to Storyline must already exist in Storyline.

So, using your example, if there was no variable called "Points" in Storyline (or if the variable was erroneously named "Point" in Storyline), player.SetVar("Points",myVariable) wouldn't work.

This discussion is closed. You can start a new discussion or contact Articulate Support.