I have been tasked with developing a dice game where the player places a bet amount and rolls the dice until they run out of money. My goal is to track the number of times the dice has been rolled before the player goes broke, and store this data in an array. I am using a do..while loop to handle the dice rolling process but I'm unsure how to keep count of the iterations and save it in an array. Any guidance on how to achieve this would be greatly appreciated!
<script>
var rolls = new Array();
var maxMoney = new Array();
var rollCountMoney = new Array();
function rollDice(){
do {
var userInput = parseInt(document.getElementById("bet").value);
var wallet = userInput;
var d1 = Math.floor(Math.random() * 6) + 1;
var d2 = Math.floor(Math.random() * 6) + 1;
var diceTotal = d1 + d2;
if(diceTotal === 7) {
document.getElementById("bet").value = wallet += 4;
alert("your rolled a " +diceTotal +"! You win $4");
} else {
document.getElementById("bet").value = wallet -= 1;
alert("your rolled a " +diceTotal +"! You lose $1");
}
} while (wallet > 0) {
}
}
</script>
</head>
<body>
<div class="container-fluid">
<div class="page-head">
<h1 align="center">Lucky Sevens</h1>
</div>
</div>
<div class="container" align="center">
<table style="border: 1px solid black">
<tr>
<th><h3 align="center">Lucky Sevens</h3></th>
</tr>
<tr>
<td>
<form>
Starting Bet:
<input id="bet" type="text"/>
</form>
</td>
</tr>
<tr>
<td align="center">
<button onclick="rollDice()">Play</button>
</td>
</tr>
</table>
</div>