HTML element:
<div style="text-align:center;";">
<input style="align:center;" type="button" value="Roll" onClick='roll()';>
</div>
JavaScript snippet:
function roll(){
document.getElementById('test5').innerHTML=roll;
var roll;
document.getElementById('test').innerHTML=roll;
if (!(roll == 1 || roll == 2 || roll == 3)){
document.getElementById('test1').innerHTML='inLoop';
roll = 1;
}
//irrelavent code
var dice1=dice[0];
var dice2=dice[1];
var dice3=dice[2];
var dice4=dice[3];
var dice5=dice[4];
if (roll>=3){
score(dice1, dice2, dice3, dice4, dice5);
}
roll = storeRoll(roll);
document.getElementById('test4').innerHTML=roll;
};
function storeRoll(roll){
++roll
document.getElementById('test2').innerHTML='inFunction';
document.getElementById('test3').innerHTML=roll;
return roll;
};
I am trying to make it so that if roll
isn't defined yet, it will set it to 1
and
at the end of the function it will add 1
to roll
. Once there are 3
rolls, it calls
the score
function. In my trial and error it seemed that the roll
variable was getting
reset every time I restart the function. I do the function multiple times at user click on an HTML input button so a loop will not work. Every time I click on the button, the roll
variable resets. I was wondering if there is something in my code that is resetting the variable roll
.