Answer the question
In order to leave comments, you need to log in
How to randomly take a key in js?
I have this code on nodejs:
when I run the script, I need to use these keys several times in the script and so that they are taken randomly, but I run the script, output them for example console.log (k) several times and I ALL 10 TIMES ONE AND SAME KEY Aaaaa WHY??7
Answer the question
In order to leave comments, you need to log in
function RandomKey() {
return key[Math.floor(Math.random() * (key.length))];
}
console.log(RandomKey());
console.log(RandomKey());
console.log(RandomKey());
Well, it's all logical. the script was loaded - fulfilled - in a variable k there is a value. of course console.log(k) will produce it.
make a function, for example, on a button click, so that the variable k is updated
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question