Javascript variable

Hello! I'm having trouble with a Javascript variable in Storyline. The lines in question are:

//Generate a random number for certificate

//Setting randomnumber to dateString because datesString works
var randomnumber = dateString;
//var randomnumber = Math.floor(Math.random() * (999999 - 100000 + 1)) + 100000;


player.SetVar("systemDate", dateString);
player.SetVar("randomNumber",randomnumber);

If I make the text box equal to %systemDate%, it returns the date. But if I make it equal to %randomNumber%, it returns %randomNumber% even when it has been set to equal the same value as system date! Am I missing some basic element of setting text boxes equal to variables?

4 Replies
Rutwin Geuverink

Happy New Year 2014!

Karessa Torgerson said:

Hello! I'm having trouble with a Javascript variable in Storyline. The lines in question are:

//Generate a random number for certificate

//Setting randomnumber to dateString because datesString works
var randomnumber = dateString;
//var randomnumber = Math.floor(Math.random() * (999999 - 100000 + 1)) + 100000;


player.SetVar("systemDate", dateString);
player.SetVar("randomNumber",randomnumber);

If I make the text box equal to %systemDate%, it returns the date. But if I make it equal to %randomNumber%, it returns %randomNumber% even when it has been set to equal the same value as system date! Am I missing some basic element of setting text boxes equal to variables?

presuming the lines above are only part of the entire script you're using, since %systemDate% wouldn't return the date with just those lines.

Not sure what you'd like to achieve here, but if you like to create a certificate number that's made up of a random number + the current date then the following code will do:

var currentTime = new Date()

var month = currentTime.getMonth()

var day = currentTime.getDate()

var year = currentTime.getYear()

var dateString=month + "" + day + "" + year;

var randomnumber = Math.floor(Math.random() * (999999 - 100000 + 1)) + 100000 + "" + dateString;

var player = GetPlayer();

player.SetVar("randomNumber",randomnumber);

player.SetVar("systemDate",dateString);

Hope this will help!

If you need any further help, let me know.