我有一個硬幣翻轉程序,我正在做一個循環。問題在於它似乎很早就退出了。看一看。Javascript退出循環提前
$(function() {
$('#rollDice').click(function() {
var e = document.getElementById("diceSides");
var diceSides = e.options[e.selectedIndex].text;
var diceRolls = document.getElementById('rollCount').value;
if (diceRolls.match(/^[\d]*$/)) {
if (diceRolls == "") {
alert ("Please fill out all forms then try again.");
} else {
$('#diceRollContainer').slideDown('slow');
for (i=0;i<diceRolls;i++) {
var randNum = Math.floor(Math.random()*diceSides)+1;
var rolls = ("You rolled a " + diceSides + " sided die " + diceRolls + " times, and got the numbers ");
rollMinOne = rolls - 1;
if (i == rollMinOne) {
var rolls = (rolls + randNum + ".");
}
var rolls = (rolls + randNum + ", ");
}
alert (rolls);
}
} else {
alert ("Make sure you only enter numbers and no spaces, then try again.");
}
});
});
的問題是,程序提醒輥之前在for循環似乎完成。它爲什麼這樣做?
如果你做console.log(diceRolls),它的價值是什麼? – tcole 2012-04-12 03:11:37
它的價值是10. – 2012-04-12 03:13:24
它提醒什麼,你期望什麼?看着這個,我希望看到類似於'你擲了一個4面的骰子3次,並得到了數字1,2,3.3,' – 2012-04-12 03:15:20