Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

select a random item from a list javascript

//This is an example of a Temporal Literal
lunchParty = ["Angela", "Ben", "Jenny", "Michael", "Chloe"];

function whosPaying(names) {
    let upperBound = names.length;
    let PersonBuyingLunch = Math.floor(Math.random() * upperBound)
    return names[PersonBuyingLunch] 
}
//below are backticks, not single quotes
alert(`${whosPaying(lunchParty)} is buying lunch today`)

whosePaying(lunchParty)
Source by developer.mozilla.org #
 
PREVIOUS NEXT
Tagged: #select #random #item #list #javascript
ADD COMMENT
Topic
Name
2+7 =