generate random words javascript code example

Example 1: javascript random word

// function for selecting a random index from an array
const pickOne = (arr) => arr[Math.floor(Math.random() * arr.length)];

let choice = pickOne(["Apple", "Banana", "Orange"]);

Example 2: js random word generator

var word = ['Rock', 'Paper', 'Scissor'];
var words = word[Math.floor(Math.random()*word.length)];
alert('The computer chose:' + wors);

// Be sure to add more to the string values if you wish to add more words.