robb33
2/23/2017 - 10:08 PM

random word explained

random word explained

//You should make an array:

var words = ['Rock', 'Paper', 'Scissors'];
//and then generate a random number between 0 and the length of the array, with 0 decimals:

var number = Math.floor(Math.random() * words.length);
//And then select the word where the key is the random nummer you just created:

var word = words[number];
//In total:

var words = ['Rock', 'Paper', 'Scissors'];
var word = words[Math.floor(Math.random() * words.length - 1)];