Javascript variable
Dec 31, 2013
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
Happy New Year 2014!
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.
Hi Karessa,
In addition to the information shared by Rutwin there is some example information at the bottom of this article on how to generate a random number including a video and a written explanation.
Hi! Happy New Year and thanks to both of you. I should have posted the code in its entirety to avoid confusion!
The thing that was broken: I did not add the variable to the variable section accessed through the x button. Oops!
Thanks again.
Thanks for the update Karessa and glad you got it figured out! Happy New Year to you as well!
This discussion is closed. You can start a new discussion or contact Articulate Support.