我不知道为什么这不起作用。一切都以正确的方式声明,语法看起来很完美。谁能告诉我怎么了?困难是从电台选择中收到的,但我已经在这里声明了。功能机器人不会收到警报。
var difficulty = "easy";
var botchance = 0;
var botroll = 0;
var botscore = 0;
function bot(){
botchance = Math.floor(Math.random() * (10 - 1 + 1)) + 1;
switch(difficulty){
case "easy":
if (botchance <= 6){
botroll = Math.floor(Math.random() * (10 - 3 + 1)) + 3;
}
else botroll=10;
break;
case "medium":
if (botchance <= 7){
botroll = Math.floor(Math.random() * (9 - 2 + 1)) + 2;
}
else botroll=10;
break;
case "hard":
if (botchance <= 8){
botroll = Math.floor(Math.random() * (8 - 1 + 1)) + 1;
}
else botroll=10;
break;
default:
if (botchance <= 9){
botroll = Math.floor(Math.random() * (7 - 1 + 1)) + 1;
}
else botroll=10;
}
alert(botscore);
alert(botroll);
}