js roll function
function roll(min, max, floatFlag) {
let r = Math.random() * (max - min) + min
return floatFlag ? r : Math.floor(r)
}
//example use case
let userNames = ['James', 'Jane', 'Ryan', 'Rebecca']
// Ages between 12 and 64
// Heights between 5.1 and 6 meters
let user = {
name: userNames[roll(0, userNames.length)],
age: roll(12, 65),
height: roll(5.1, 6.1, 1).toFixed(1)
}
console.log(user)
Also in JavaScript:
- javascript check if any value in array is true
- best javascript ide
- check if set has value js
- javascript glow
- react replace all line breaks with br
- how the sort function works javascript
- js fetch delete
- string.contains javascript
- html how to hide and show multiple
- how reliable is js hasownproperty
- moment hour minute
- discord js check every x minutes
- package json proxy
- check if element has childs jquery
- javascript keywords
- how to display text one after one from an array with 2 seconds delay in react
- redis nodejs
- js copy to clipboard cross browser
- how to lock device orientation using css and javascript
- visual studio code create react component shortcut
- javascript convert string to bool
- resize image react native
- bs modal service close
- dynamic page in html