1//get random value from array
2var colors = ["red","blue","green","yellow"];
3var randColor = colors[Math.floor(Math.random() * colors.length)];
4
1var foodItems = ["Bannana", "Apple", "Orange"];
2var theFood = foodItems[Math.floor(Math.random() * foodItems.length)];
3/* Will pick a random number from the length of the array and will go to the
4corosponding number in the array E.G: 0 = Bannana */
1var items = ['Yes', 'No', 'Maybe'];
2var item = items[Math.floor(Math.random() * items.length)];
1// how to generate random words from an array
2const Coins = ["Heads","Tails"]
3let Generate = Math.floor((Math.random() * Coins.length));
4
5console.log(Coins[Generate]) // this will print the outcome
1function getRandomNumberArr(bound, length) {
2 return Array.from({ length }, () =>
3 Math.floor((Math.random() - 0.5) * 2 * bound)
4 );
5}
6
7const randomArray = getRandomNumberArr(100, 200);