我想確定什麼是總和等於,然後做一個有關每個選擇的工作。我的第一選擇是如果總數是2,3或12,那麼你輸了。如果它是一個7或11,你輸了。除此之外的任何其他事情都已確立。首先我的代碼看起來像這樣,但每一次,它都去了其他的。價值錯誤的選擇
Math.floor(Math.random()*6+1);
function game()
{
if(total==2 || total==3 || total==12)
{
alert("You lose. Please start a New Round");
}
if(total==7 || total==11)
{
var temp= 2 * bet;
alert("You win $" + temp);
}
else
{
alert("Point Established. Roll again.");
var point=total;
setTimeout(rolldice2,3000);
}
}
於是我改成了這樣::總正在通過2噸使用此功能加在一起的隨機數計算
function game()
{
if(total==2 , 3 , 12)
{
alert("You lose. Please start a New Round");
return;
}
if(total==7 , 11)
{
var temp= 2 * bet;
alert("You win $" + temp);
return;
}
else
{
alert("Point Established. Roll again.");
var point=total;
setTimeout(rolldice2,3000);
}
}
,但它只是說,你輸了無論。然後我終於拿出了回報。它做了第一個2而不是其他的。我希望能夠選擇一個 - 取決於變量總數是否相等 - 然後執行其作業,然後離開該功能。
你在哪裏,在計算總? – krillgar
儘管我很欣賞擲骰子,但您提供的代碼並未向我們透露足夠的信息,以幫助 – whitneyit
之前的計算總數。我沒有包括它,因爲它計算得很好。我知道這是因爲它顯示總數,然後執行上述功能。這是問題發生的地方。 Math.floor(Math.random()* 6 + 1); – Patrick