Ideas to Inspire #1

Here is a small project with a relatively simple idea: Generate Random Letters
I share with you the two lines of JavaScript needed to make this work

Link to Project

I would love to hear about the different ways that you can think of to use random letter generation in your own projects. Please share them in the comments.

2 Likes

Hi Greg,

Thank you for sharing your creative project idea and the JavaScript code for generating random letters.
After reviewing your project, we see that instead of creating each state for each letter which takes time, you can use the function object.text('new text') to change letter prez.object('tile').text(String.fromCharCode(prez.variable('num') + 64));

In addition, your random number generation from 1 to 26 is not quite accurate (it can generate 0, and is not evenly distributed). So, you can fix it by referring to the suggestion here: Generate random number between two numbers in JavaScript - Stack Overflow

Nice day,
Thuy

1 Like

I am familiar with the Math.floor() method as well.
I have often preferred the Math.ceil version as it always seemed to do the same thing without issue.
As I was thinking more critically about this, however, it came to light that it is possible Math.random() could produce a perfect zero - in which case - the result would remain as zero. I must admit I had not considered this nor do I think I have had it happen but I do see now the better logic of using the Math.floor() method instead.

Using the idea regarding object.text(‘new text’) is one that I had not considered. Interesting approach to play with. Thank you.

1 Like