Raj
0
Q:

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)
0

New to Communities?

Join the community