xxxxxxxxxx
43
const playerInput = document.querySelector('#players')
const roundsInput = document.querySelector('#rounds')
const result = document.querySelector('pre')
playerInput.addEventListener('input', e => {
sanitize(playerInput, 1, 30)
runGame()
})
roundsInput.addEventListener('input', e => {
sanitize(roundsInput, 1, 30)
runGame()
})
function sanitize(element, min, max) {
if (!element.value || element.value < min) {
element.value = min
}
if (element.value > max) {
element.value = max
}
if (!Number.isInteger(element.value)) {
element.value = Math.floor(element.value)
}
}
function runGame() {
players = Number(playerInput.value) || 1
rounds = Number(roundsInput.value) || 1
let amounts = []
while (amounts.length < players) {
thisAmount = 100
for (let i = 0; i < rounds; i++) {
const multiplier = Math.random() < 0.5 ? 1.5 : 0.6
thisAmount *= multiplier
}
amounts.push(thisAmount)
}
amounts = amounts.map(a =>
a.toFixed(2))
result.innerHTML = amounts.join('<br>')
}