我正在编写这样的 JavaScript 代码:
function rollTrigger() {
var roll = Math.round(Math.random()*999999999+1);
var result = document.getElementById("result");
if (roll <= 50900000) {
result.innerHTML = "Category 0";
BoLPamount += 1;
document.getElementById("boxlesserprizes").innerHTML = "Box of Lesser Prizes " + BoLPamount;
log.innerHTML += "<br />Trigger - win = true; Category 0"; //LOG
} else if (roll <= 900000) {
result.innerHTML = "Category A";
log.innerHTML += "<br />Trigger - win = true; Category A"; //LOG
} else if (roll <= 360000) {
result.innerHTML = "Category B";
log.innerHTML += "<br />Trigger - win = true; Category B"; //LOG
} else if (roll <= 211890) {
result.innerHTML = "Category C";
log.innerHTML += "<br />Trigger - win = true; Category C"; //LOG
} else if (roll <= 109020) {
result.innerHTML = "Category D";
log.innerHTML += "<br />Trigger - win = true; Category D"; //LOG
} else if (roll <= 56505) {
result.innerHTML = "Category E";
log.innerHTML += "<br />Trigger - win = true; Category E"; //LOG
} else if (roll <= 34888) {
result.innerHTML = "Category F";
log.innerHTML += "<br />Trigger - win = true; Category F"; //LOG
} else if (roll <= 15574) {
result.innerHTML = "Category G";
log.innerHTML += "<br />Trigger - win = true; Category G"; //LOG
} else {
result.innerHTML = "MEH";
log.innerHTML += "<br />Trigger - win = false"; //LOG
};
document.getElementById("roll").innerHTML = roll;
};
但它不能正常工作......例如,如果随机数是 40200000,那么它会按预期显示“类别 0”,但是即使随机数是 10,它仍然显示“类别 0”而不是“类别 G”。知道有什么问题吗?