Random word generator
Jul 06, 2015
We're wanting to use a method to ensure that our students complete all three activities by rewarding students with 3 randomly generated words that combined will let the teacher know that they completed all of the activities. In other words:
Activity 1 - The student gets a randomly password from a bank of 5 (Probably using a JavaScript array) for that activity. The same would happen for activities 2 and 3.
Activity 4 - The student inserts the passcodes from the 3 previous activities and if they are correct (This storyline would check to see if they match to any 5 of the bank) if all 3 are correct they can let the teacher know that they have completed all the activities.
Is this possible to do in JavaScript? If so what would the code look like? Or is there away to do this using variables in Storyline already?
9 Replies
Here are (JS and Non-JS) examples to generate random numbers, this could also be adapted to randomly pick words.
See I thought in theory this would work:
Is there something I'm doing incorrectly?
The screenshot is too small, I can't see the script details. Are you testing locally? In that case the Javascript may also be blocked by Flash player security settings.
Yes I'm testing locally. I'm using the story_html5.html to do my testing. Here's the code I'm using:
var selectFruit = ["Apple", "Orange", "Banana", "Cherry"];
var pickAFruit = function () {
var todaysFruit = selectFruit[Math.floor(Math.random() * 4)];
player.SetVar("random", todaysFruit;)
};
I'm by no means a Javascript expert but I found examples of what I'm looking for using just JavaScript alone. I think what I'm having problems with is to actually get the variable to actually display in a textbox when I reference the variable the Javascript creates.
I can't test this out right now, but at the very least, this line is missing:
var player = GetPlayer();
and it should be: player.SetVar("random", todaysFruit);
Here's the file I'm working with. It's just super simple right now.
This works:
var player = GetPlayer();
var selectFruit = ["Apple", "Orange", "Banana", "Cherry"];
var todaysFruit = selectFruit[Math.floor(Math.random() * 4)];
player.SetVar("random", todaysFruit);
Yay it works! That's awesome! Thanks for all your help!
Good luck with your project!
This discussion is closed. You can start a new discussion or contact Articulate Support.