trying to generate a random number using javascript
Sep 24, 2014
Okay iv'e spent the past several hours trying to get this to work, following every tutorial iv'e found on the web step by step and not sure where i'm getting it wrong.
I want to have a button that when clicked it generates a random number between 1-10.
So these are the steps iv'e taken exactly from scratch....
(1) create a textbox
(2) click REFERENCE and create a new VARIABLE
(3) name the variable randnum (set it as a number, with a value of 0)
(4) create a trigger for the button
(5) set button so - when user clicks button, javascript is executed.
(6) add the following javascript:
var randomnumber = Math.floor((Math.random()*10)+1);
var player = GetPlayer();
player.SetVar("randnum",randomnumber);
iv'e attached the storyline file
Nate
7 Replies
Are you testing locally (on your harddrive)? In that case, the script may be blocked my your browser's security settings. Upload to some server and test again. You script works for me, see here.
Nate,
I published and ran your file using Storyline 2 and it worked great. It randomly generated a number as advertised. I couldn't find anything that would cause your issue. BTW - I published for CD to test it.
Oh thankyou for testing it,
I actually plan to use this as a SWF file, but i won't be uploading it onto a server. Do you know if there is a way around it within articulate without uploading it onto a server?
Aha!
Looks like I need to publish it for CD.
Thank-you for the help
How can I modify to only generate 1,2 or 3?
Hi Eric -
Changing the random generator to this should get you a number from 1 to 3:
var randomnumber = Math.floor((Math.random()*3)+1);
This discussion is closed. You can start a new discussion or contact Articulate Support.