N
N
Nikita NeVajno2020-04-21 23:50:18
JavaScript
Nikita NeVajno, 2020-04-21 23:50:18

How to assign random letters to a variable?

I want to make a command for discord so that it randomly displays a word from English letters. The number of letters is 18.
The problem is that I don't know how to do it. Here is Math.ceil(), but it is for numbers. And I wanted the same for letters.
If I do it through a function, then in response to the command I get function makeid ()
Here is the code:

var random = function makeid()
{
    var text = "";
    var possible = "abcdefghijklmnopqrstuvwxyz";
    for( var i=0; i < 18; i++ )
        text += possible.charAt(Math.floor(Math.random() * possible.length));
    return text;
}

An excerpt from the command code:
msg.channel.send(random)
When I enter the command, I get what is after = in var.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
RomanKudlatov, 2020-04-21
@Pangsit

The function must be called
msg.channel.send(random());

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question