Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

how to put variable in string 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: #put #variable #string #javascript
ADD COMMENT
Topic
Name
2+9 =