我试图获得一个计数器来记录获得双倍所需的最少数量的掷骰,然后当他们玩#39;游戏时再次,如果他们的双打数量更少,则用新的替换第一个答案。
count=0, doubles=0, lowest=10000000;
function Roll()
// Assumes: die images are in http://dave-reed.com/book/Images
// Results: displays a randomly selected image of a 6-sided die
{
var roll1, roll2;
roll1 = RandomInt(1, 6);
roll2 = RandomInt(1, 6);
document.getElementById('die1').src =
"http://dave-reed.com/book/Images/die" + roll1 + ".gif";
document.getElementById('die2').src =
"http://dave-reed.com/book/Images/die" + roll2 + ".gif";
count += 1;
if (roll1==roll2) {
doubles += 1;
}
if (doubles==3) {
alert("You got three pairs of doubles!!! It only took you " +count+ " rolls to get it! Now, go directly to jail, do not pass go, and do not collect $200");
doubles=0;
count=0;
}
if (doubles==3 && lowest>count){
lowest=count
document.getElementById('lowestLine').innerHTML = count;
}
document.getElementById('countLine').innerHTML = count;
document.getElementById('doublesLine').innerHTML = doubles;
}
答案 0 :(得分:1)
一旦它变为3,你就将operator
设置为0,然后检查doubles
是否等于3,这是永远不会的。
看起来你应该把
doubles
在第一次if (lowest > count) {
lowest = count
document.getElementById('lowestLine').innerHTML = count;
}
内检查,但在将全局变量设置为doubles === 3
之前。
像这样:
0