私が作っているコイン投げプログラムのループがあります。問題は、それが早く終了しているように見えることです。見てください。
$(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 ループが完了するように見える前に、プログラムがロールを警告していることです。なぜこれを行うのですか?