Рассмотрим написание функций, которые принимают входные данные и выдают выходные данные -
const roll = (sides = 6) =>
Math.floor(Math.random() * sides) + 1
const isWin = (sum, bet) =>
(sum & 1) === bet
const update = (bet, state) =>
{ const d1 = roll()
const d2 = roll()
const sum = d1 + d2
return Object.assign
( state
, { d1, d2, sum }
, isWin(sum, bet)
? { win: state.win + 1 }
: { loss: state.loss + 1 }
)
}
const render = (form, state) =>
Object
.entries(state)
.forEach(([ k, v ]) => form[k].value = v)
const play = (form, bet, state) =>
render
( form
, update(bet, state)
)
// init
const state =
{ d1: 0, d2: 0, sum: 0, win: 0, loss: 0 }
const f = document.querySelector("form")
f.evenbet.addEventListener("click", event => play(f, 0, state))
f.oddbet.addEventListener("click", event => play(f, 1, state))
render(f, state)
<form>
Dice: <output name="d1"></output> <output name="d2"></output><br>
Sum: <output name="sum"></output><br>
<br>
Win: <output name="win"></output>
Loss: <output name="loss"></output><br>
Bet:
<button type="button" name="oddbet">Odd</button>
<button type="button" name="evenbet">Even</button>
</form>