O
O
olezhenka2017-03-30 10:42:43
JavaScript
olezhenka, 2017-03-30 10:42:43

How to randomly take a key in js?

I have this code on nodejs:
725b32e32da344869cb60bcfe605bdc8.PNG
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

2 answer(s)
I
Ildar Gizetdinov, 2017-03-30
@olezhenka

function RandomKey() {
return key[Math.floor(Math.random() * (key.length))];
}

console.log(RandomKey());
console.log(RandomKey());
console.log(RandomKey());

I
iBird Rose, 2017-03-30
@iiiBird

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 question

Ask a Question

731 491 924 answers to any question