how to get a random element of an array javascript
var foodItems =["Bannana","Apple","Orange"];var theFood = foodItems[Math.floor(Math.random()* foodItems.length)];/* Will pick a random number from the length of the array and will go to the
corosponding number in the array E.G: 0 = Bannana */
let fruits =["Apple","Banana","Mango","Orange"];// arraylet index =Math.floor(Math.random()* fruits.length);// random indexconsole.log(fruits[index]);// result
const array =[1,2,3,4,5,6,7,8,9];const string ="abcdefghijklmnopqrstuvwxyz";// random item from Arrayconsole.log(array[Math.floor(Math.random()* array.length)]);// random Char from Stringconsole.log(string[Math.floor(Math.random()* string.length)]);
//This is an example of a Temporal Literal
lunchParty =["Angela","Ben","Jenny","Michael","Chloe"];functionwhosPaying(names){let upperBound = names.length;letPersonBuyingLunch=Math.floor(Math.random()* upperBound)return names[PersonBuyingLunch]}//below are backticks, not single quotesalert(`${whosPaying(lunchParty)} is buying lunch today`)whosePaying(lunchParty)