Idea #1 in the JavaScript Idea Series – Choosing a Random Letter
You may have wondered about or even implemented the idea of random numbers but have you ever thought about selecting a random letter?
Here is one way of making this work. I would love to hear about some ways you might be able to use random letters in your projects. Please share them in the comments. Feel free to share any questions that you may have.
A working sample with code is below.
Used a similar approach but not for letters, when choosing a random image (from a multistate object).
You can also limit the number of letters to those of a particular word to present them in a shuffled sequence for a game where that words needs to be composed (by D&D).
Randomization opens up a world of possibilities.
Concatenation with variables and multistate objects is one strategy.
Another strategy I plan to demonstrate related to randomization is using arrays – which are great for many sorts of word games. I used arrays in the realization of the Hangman and Animal Spelling projects.
I gave up pleading to have concatenation in the Advanced Actions dialog box, because that would create lot of new possibilities and simplify many actions.
As you know I prefer shared/advanced actions, but use JS for three goals: randomization (of course), formatting of numbers/dates and arrays. Randomization is the number 1 without any doubt.
…
Hello and thank you (again) Greg !…
Here is my contribution :
In France, we used to play a game when I was a child which was called “le baccalauréat“…
It was a game of vocabulary… We have to pick up a letter (For this purpose we used to open a dictionary on a random page and select the corresponding letter !) and complete a table with categories like “animal”, “geography”, “names”, “jobs”, “plants”… and whatever you want. The first letter of each words must be the selected letter.
Of course we could elaborate on such a game with your idea of randomly select a letter !…
😉
…
…
Done !…
A first try… But already happy with it !…
http://soutien67.fr/francais/activites/vocabulaire/Baccalaureat_01/index.html
Thanks again so !…
😉
…
Hello! Hoping you guys can help me figure out what I have done wrong. I created a variable named “num” the type is number.
The trigger – Execute JavaScript JavaScript when the user clicks button
JavaScript:
var num = Math.floor(Math.random() * 26) + 1;
cp.changeState(“letterBox”,”letter”+num);
Rhoda
Just got a notification about this post a few hours ago but it says 5 days ago here…?
Anyway – sorry if it has actually been that long.
This idea depends on having a series of states for an object named letterBox
where all of the state names follow the same pattern letter1, letter2, letter3, etc
These names are case sensitive. Can you verify that you have an object named letterBox with 26 additional states named letter1 thru letter26?
You must be logged in to post a comment.