Hi I’ve made a code that rolls dice untill it gets doubles, I’m trying to make a Counter for it so that it counts how many times it rolls untill it gets doubles. Can someone help me get the counter to work?
[CODE]<html>
<!– roll.html –>
<!—————————————————————->
<head>
<title> Dice Stats </title>
<script type=”text/javascript”
src=”http://www.prenhall.com/reed/random.js”>
</script>
<script type=”text/javascript”>
function RollUntilDoubles()
// Assumes: document.DiceForm.Output is available for output
// Results: rolls and displays dice until doubles are obtained
{
var roll1, roll2, repCount;
repCount = 0;
while (repCount > 0) {
roll1 = RandomInt(1, 6); // roll and display dice
roll2 = RandomInt(1, 6);
document.DiceForm.Output.value =
“You rolled: ” + roll1 + ” ” + roll2 + “n”;
while (roll1 != roll2) { // while not doubles,
roll1 = RandomInt(1, 6); // roll again and display
roll2 = RandomInt(1, 6);
document.DiceForm.Output.value =
document.DiceForm.Output.value +
“You rolled: ” + roll1 + ” ” + roll2 + “n”;
}
document.DiceForm.Output.value =
document.DiceForm.Output.value + “DOUBLES!”;
document.DiceForm.count.value =
document.DiceForm.count.value + repCount;
}
</script>
</head>
<body>
<div style=”text-align:center”>
<form name=”DiceForm”>
<input type=”button” value=”Roll until doubles”
onClick=”RollUntilDoubles();” />
<br /><br />
<textarea name=Output rows=20 cols=20 wrap=”virtual”></textarea>
<input type=”text” name=”count” size=6 value=0 />
</form>
</div>
</body>
</html>