Javascript 当我在2人模式下运行代码时,函数rounda和roundb不';不回答

Javascript 当我在2人模式下运行代码时,函数rounda和roundb不';不回答,javascript,Javascript,当我的代码运行时,我进入2播放器模式并调用函数rounda和roundb,由于某种原因它们没有响应。其他一切都很好,但我不知道怎么了。提前感谢您提供的任何可能的建议。我的代码如下。我调用函数的位置在底部 var a = Math.floor(Math.random() * 7) + 1; var da = null; var ga = null; if (a === 1) { da = "Monday"; } else if (a === 2) { da = "Tuesday

当我的代码运行时,我进入2播放器模式并调用函数rounda和roundb,由于某种原因它们没有响应。其他一切都很好,但我不知道怎么了。提前感谢您提供的任何可能的建议。我的代码如下。我调用函数的位置在底部

var a = Math.floor(Math.random() * 7) + 1;

var da = null;

var ga = null;

if (a === 1) {

  da = "Monday";

} else if (a === 2) {

  da = "Tuesday";

} else if (a === 3) {

  da = "Wednesday";

} else if (a === 4) {

  da = "Thursday";

} else if (a === 5) {

  da = "Friday";

} else if (a === 6) {

  da = "Saturday";

} else if (a === 7) {

  da = "Sunday";

}

var play = prompt("Please select either 1 or 2 players! Have at least 5000 credits at the end to win!");

if (play === "1") {

  var wel = confirm("On a stormy " + da + " night, lightning lurks the skies. Will you risk your business for a chance to make millions?");

} else if (play === "2") {

  confirm("On a stormy " + da + " night, lightning lurks the skies. Two electricity distributors compete head to head for dominance over the electric market. Who will reign supreme?");

} else {

  ga = 1;

}

var ezR1 = Math.floor((Math.random() * 2560) + 500);

var ezR2 = Math.floor((Math.random() * 6650) + 500);

var ezR3 = Math.floor((Math.random() * 6670) + 600);

var ezR4 = Math.floor((Math.random() * 7780) + 600);

var ezR5 = Math.floor((Math.random() * 8120) + 700);

var ezR6 = Math.floor((Math.random() * 9540) + 700);

var ezR7 = Math.floor((Math.random() * 1230) + 800);

var ezR8 = Math.floor((Math.random() * 1134) + 800);

var ezR9 = Math.floor((Math.random() * 1223) + 900);

var ezR10 = Math.floor((Math.random() * 1510) + 1000);

var ezR1a = Math.floor((Math.random() * 2560) + 500);

var ezR2a = Math.floor((Math.random() * 6650) + 500);

var ezR3a = Math.floor((Math.random() * 6670) + 600);

var ezR4a = Math.floor((Math.random() * 7780) + 600);

var ezR5a = Math.floor((Math.random() * 8120) + 700);

var ezR6a = Math.floor((Math.random() * 9540) + 700);

var ezR7a = Math.floor((Math.random() * 1230) + 800);

var ezR8a = Math.floor((Math.random() * 1134) + 800);

var ezR9a = Math.floor((Math.random() * 1223) + 900);

var ezR10a = Math.floor((Math.random() * 1510) + 1000);

var ezR1b = Math.floor((Math.random() * 2560) + 500);

var ezR2b = Math.floor((Math.random() * 6650) + 500);

var ezR3b = Math.floor((Math.random() * 6670) + 600);

var ezR4b = Math.floor((Math.random() * 7780) + 600);

var ezR5b = Math.floor((Math.random() * 8120) + 700);

var ezR6b = Math.floor((Math.random() * 9540) + 700);

var ezR7b = Math.floor((Math.random() * 1230) + 800);

var ezR8b = Math.floor((Math.random() * 1134) + 800);

var ezR9b = Math.floor((Math.random() * 1223) + 900);

var ezR10b = Math.floor((Math.random() * 1510) + 1000);

var choozMany = Math.floor((Math.random() * 4) + 1);

var chooz = Math.random();

var amountOfPower = null;

var money = null;

var moneya = null;

var moneyb = null;

var cabels = 5;

var clients = 2;

var bacout = 1;

var one = 1;

var d = 0;

var da = 0;

var db = 0;

var vas = true;

var vasa = true;

var vasb = true;

var cabelsTake = 500 * cabels;

var bacoutTake = 2000 * bacout;

var valu = "a";

var valua = "a";

var valub = "a";

var gunka = true;

var gunkb = true;

var cabelsa = 5;

var clientsa = 2;

var bacouta = 1;

var cabelsb = 5;

var clientsb = 2;

var bacoutb = 1;


function Round(x) {

  alert("Round " + x + " has begun!");

}


function s() {

  console.log(" ");

}


function Tell(a, b, c, d, z, e) {

  s();

  console.log("***********************************");

  if(e === n1 || e === n2){

  console.log("ROUND " + z + "(" + e + ")");

  } else {


   console.log("ROUND " + z);

  }



  console.log("-----------------------------------");

  console.log("Credits: " + a);

  console.log("Power Cabels: " + b);

  console.log("Back Outputters: " + c);

  console.log("Clients: " + d);

  console.log("-----------------------------------");

}


function Strike(x) {

  console.log("⚡ KABOOM! ⚡");

  console.log("Lightning strike power: " + x + " Volts");

}


function blowCable() {

  console.log("Oh No! Some of your cables have blown up! You have " + cabels + " left!");

}


function blowBacout() {

  console.log("Oh No! Some of your backup outputters have blown up! You have " + bacout + " left!");

}

// Logic(cabelsTake, bacoutTake, clients, cabels, ezRX,);

function Logic(a, b, c, d, e) {

  var total = e - a;

  var out = total - b;

  var yon = a - e;

  var cab = 500 * d;

  if (yon > 0) {

    var moneyEarned = e / 2 * c + cab;

    var result = Math.round(moneyEarned);

    money += result;

    console.log("-----------------------------------");

    console.log("Credits Earned: " + result);

    console.log("Cables/Backup Outputters Overridden: None");

    console.log("***********************************");

    s();

  } else {

    console.log(" ");

    console.log("ALERT! ALERT! Too much power!");

    console.log(" ");

    console.log("Attempting to send power to Backup Outputter... ");

    console.log("⚠️BREACH! BREACH! OUTPUTTER INVALID! ATTEMPTING TO RESEND...⚠️");

    console.log("***********************************");

    s();

    if (out < 0) {

      var pen = 3000 + cab;

      money += pen;

      console.log("***********************************");

      console.log("Success! Power diverted.");

      console.log("Credits Earned: " + pen);

      console.log("***********************************");

      s();

    } else {

      console.log("WARNING! Input to large!");

      if (chooz < 0.75 && cabels > 0) {

        cabels -= choozMany;

        blowCable();

        console.log("Cables/Backup Outputters Overridden: " + choozMany);

        console.log("***********************************");

      } else if (chooz > 0.75 && bacout > 0) {

        bacout -= choozMany;

        blowBacout();

        console.log("Cables/Backup Outputters Overridden: " + choozMany);

        console.log("***********************************");

        s();

      }

    }

  }

}

//round('round number', 'ezRX' )

function round(x, y) {

  if (d < 1 && valu === "a") {} else if (valu === "a" && vas === true) {

    alert("Press 'ok' to move on to the next round");

  }

  if (valu === "a" && money > 3000) {

    var shop = prompt("Shop Round " + x + ": 1.Power cable-$3000  2.Backup Outputter-$5000 3. Extra client-$30,000            Credits: " + "$" + money);

    if (shop === "1" && money >= 3000) {

      //cabels += one; works, money -= 1000; works

      cabels += one;

      money -= 3000;

      cabelsTake = 500 * cabels;

      bacoutTake = 2000 * bacout;

      //Round x

      Round(x);

      Tell(money, cabels, bacout, clients, x);

      Strike(y);

      Logic(cabelsTake, bacoutTake, clients, cabels, y);

      d++;

    } else if (shop === "2" && money >= 5000) {

      money -= 5000;

      cabelsTake = 500 * cabels;

      bacoutTake = 2000 * bacout;

      bacout += one;

      //Round x

      Round(x);

      Tell(money, cabels, bacout, clients, x);

      Strike(y);

      Logic(cabelsTake, bacoutTake, clients, cabels, y);

      d++;

    } else if (shop === "3" && money >= 30000) {

      money -= 30000;

      cabelsTake = 500 * cabels;

      bacoutTake = 2000 * bacout;

      clients += one;

      //Round x

      Round(x);

      Tell(money, cabels, bacout, clients, x);

      Strike(y);

      Logic(cabelsTake, bacoutTake, clients, cabels, y);

      d++;

    } else {

      var g = money / 2;

      if (money < 3000) {

        valu = "b";

      } else {

        money -= g;

        console.log("You lost " + g + " credits for skipping a turn.");

        if (money < 3000) {

          console.log("------------------");

          console.log("GAME OVER! Thanks for playing.");

          valu = "b";

          vas = false;

        }

      }

    }

    if (bacout <= 0 || cabels <= 0) {

      valu = "b";

    }

  }

  if (valu === "b" && vas === true) {

    console.log("------------------");

    console.log("GAME OVER! Thanks for playing.");

    valu = "b";

    vas = false;

  }

  if (d === 10) {

    if (money > 5000 && valu === "a") {

      console.log("Congratulations! You have made it through the storm. Your business continues to make millions!");

    } else {

      console.log("Oh No! You don't have enough money! Your business crumbles into chaos!");

    }

    valu = "b";

    vas = false;

  }

}

// Logic(cabelsTake, bacoutTake, clients, cabels, ezRX,);

//-------------------------------------------

function Logica(a, b, c, d, e) {

  var total = e - a;

  var out = total - b;

  var yon = a - e;

  var cab = 500 * d;

  if (yon > 0) {

    var moneyEarned = e / 2 * c + cab;

    var result = Math.round(moneyEarned);

    moneya += result;

    console.log("-----------------------------------");

    console.log("Credits Earned: " + result);

    console.log("Cables/Backup Outputters Overridden: None");

    console.log("***********************************");

    s();

  } else {

    console.log(" ");

    console.log("ALERT! ALERT! Too much power!");

    console.log(" ");

    console.log("Attempting to send power to Backup Outputter... ");

    console.log("⚠️BREACH! BREACH! OUTPUTTER INVALID! ATTEMPTING TO RESEND...⚠️");

    console.log("***********************************");

    s();

    if (out < 0) {

      var pen = 3000 + cab;

      moneya += pen;

      console.log("***********************************");

      console.log("Success! Power diverted.");

      console.log("Credits Earned: " + pen);

      console.log("***********************************");

      s();

    } else {

      console.log("WARNING! Input to large!");

      if (chooz < 0.75 && cabels > 0) {

        cabels -= choozMany;

        blowCable();

        console.log("Cables/Backup Outputters Overridden: " + choozMany);

        console.log("***********************************");

        s();

      } else if (chooz > 0.75 && bacout > 0) {

        bacout -= choozMany;

        blowBacout();

        console.log("Cables/Backup Outputters Overridden: " + choozMany);

        console.log("***********************************");

        s();

      }

    }

  }

}


//round('round number', 'ezRX' )

function rounda(x, y) {

  if (da < 1 && valua === "a") {} else if (valua === "a" && vasa === true && valub === true) {

    alert("Press 'ok' to move on to the next round");

  }

  if (valua === "a" && moneya > 3000 && valub === "a") {

    nexd(n1);

    var shopa = prompt("Shop Round " + x + ": 1.Power cable-$3000  2.Backup Outputter-$5000 3. Extra client-$30,000            Credits: " + "$" + moneya);

    if (shopa === "1" && moneya >= 3000) {

      //cabels += one; works, money -= 1000; works

      cabelsa += one;

      moneya -= 3000;

      cabelsTake = 500 * cabelsa;

      bacoutTake = 2000 * bacouta;

      //Round x

      Round(x);

      Tell(moneya, cabelsa, bacouta, clientsa, x, n1);

      Strike(y);

      Logica(cabelsTake, bacoutTake, clientsa, cabelsa, y);

      da++;

    } else if (shopa === "2" && moneya >= 5000) {

      moneya -= 5000;

      cabelsTake = 500 * cabelsa;

      bacoutTake = 2000 * bacouta;

      bacouta += one;

      //Round x

      Round(x);

      Tell(moneya, cabelsa, bacouta, clientsa, x, n1);

      Strike(y);

      Logica(cabelsTake, bacoutTake, clientsa, cabelsa, y);

      da++;

    } else if (shopa === "3" && moneya >= 30000) {

      moneya -= 30000;

      cabelsTake = 500 * cabelsa;

      bacoutTake = 2000 * bacouta;

      clientsa += one;

      //Round x

      Round(x);

      Tell(moneya, cabelsa, bacouta, clientsa, x, n1);

      Strike(y);

      Logica(cabelsTake, bacoutTake, clientsa, cabelsa, y);

      da++;

    } else {

      var g = moneya / 2;

      if (g < 3000 && gunka === true && gunkb === true) {

        console.log(n1 + " Eliminated!");

        console.log(n2 + " wins!");

        gunka = false;

        gunkb = false;

        valua = "b";

        valub = "b";

      } else {

        moneya -= g;

        console.log("You lost " + g + " credits for skipping a turn!");

      }

    }

  } else {}

  //Prototype

  var tosta = moneya + cabelsTake + bacoutTake + clientsa * 100;

  var tostb = moneyb + cabelsTake + bacoutTake + clientsb * 100;

  if (bacouta <= 0 || cabelsa <= 0 && gunka === true) {

    console.log(n1 + " Eliminated!");

    console.log(n2 + " wins with a total of " + tostb + " Points!");

    gunka = false;

    gunkb = false;

    valua = "b";

    valub = "b";

  }

  if (bacoutb <= 0 || cabelsb <= 0 && gunkb === true) {

    console.log(n2 + " Eliminated!");

    console.log(n1 + " wins with a total of " + tosta + " Points!");

    gunka = false;

    gunkb = false;

    valua = "b";

    valub = "b";

  }


}



//round('round number', 'ezRX' )

function roundb(x, y) {

  if (db < 1 && valub === "a") {} else if (valua === "a" && vasb === true && valub === true) {

    alert("Press 'ok' to move on to the next round");

  }

  if (valua === "a" && moneyb > 3000 && valub === "a") {

    nexd(n2);

    var shopb = prompt("Shop Round " + x + ": 1.Power cable-$3000  2.Backup Outputter-$5000 3. Extra client-$30,000            Credits: " + "$" + moneya);

    if (shopb === "1" && moneyb >= 3000) {

      //cabels += one; works, money -= 1000; works

      cabelsb += one;

      moneyb -= 3000;

      cabelsTake = 500 * cabelsb;

      bacoutTake = 2000 * bacoutb;

      //Round x

      Round(x);

      Tell(moneyb, cabelb, bacoutb, clientsb, x, n2);

      Strike(y);

      Logica(cabelsTake, bacoutTake, clientsb, cabelsb, y);

      db++;

    } else if (shopb === "2" && moneyb >= 5000) {

      moneyb -= 5000;

      cabelsTake = 500 * cabelsb;

      bacoutTake = 2000 * bacoutb;

      bacoutb += one;

      //Round x

      Round(x);

      Tell(moneyb, cabelb, bacoutb, clientsb, x, n2);

      Strike(y);

      Logica(cabelsTake, bacoutTake, clientsb, cabelsb, y);

      db++;

    } else if (shopb === "3" && moneyb >= 30000) {

      moneyb -= 30000;

      cabelsTake = 500 * cabelsb;

      bacoutTake = 2000 * bacoutb;

      clientsb += one;

      //Round x

      Round(x);

      Tell(moneyb, cabelb, bacoutb, clientsb, x, n2);

      Strike(y);

      Logica(cabelsTake, bacoutTake, clientsb, cabelsb, y);

      db++;

    } else {

      var g = moneyb / 2;

      if (g < 3000 && gunka === true && gunkb === true) {

        console.log(n2 + " Eliminated!");

        console.log(n1 + " wins!");

        gunka = false;

        gunkb = false;

        valua = "b";

        valub = "b";

      } else {

        moneyab -= g;

        console.log("You lost " + g + " credits for skipping a turn!");

      }

    }

  } else {}

  //Prototype

  var tosta = moneya + cabelsTake + bacoutTake + clientsa * 100;

  var tostb = moneyb + cabelsTake + bacoutTake + clientsb * 100;

  if (bacoutb <= 0 || cabelsb <= 0 && gunkb === true) {

    console.log(n2 + " Eliminated!");

    console.log(n1 + " wins with a total of " + tosta + " Points!");

    gunka = false;

    gunkb = false;

    valua = "b";

    valub = "b";

  }

  if (bacouta <= 0 || cabelsa <= 0 && gunka === true) {

    console.log(n1 + " Eliminated!");

    console.log(n2 + " wins with a total of " + tostb + " Points!");

    gunka = false;

    gunkb = false;

    valua = "b";

    valub = "b";

  }

  if (db === 10) {

    if (valua === "a" && valub === "a") {


        compare(tosta, tostb, n1, n2);

    } else {}

  }

}






if (play === "1") {

  //Start rounds

  money = 15000;

  round(1, ezR1);

  round(2, ezR2);

  round(3, ezR3);

  round(4, ezR4);

  round(5, ezR5);

  round(6, ezR6);

  round(7, ezR7);

  round(8, ezR8);

  round(9, ezR9);

  round(10, ezR10);

} else if (play === "2") {



var check = alert("Welcome to 2 player mode!");



    var n1 = prompt("Input Player 1's username.");

    var n2 = prompt("Input Player 2's username.");



    rounda(1, ezR1a );

    roundb(1, ezR1b );



    rounda(2, ezR2a );

    roundb(2, ezR2b );



    rounda(3, ezR3a );

    roundb(3, ezR3b );



    rounda(4, ezR4a );

    roundb(4, ezR4b );



    rounda(5, ezR5a );

    roundb(5, ezR5b );



    rounda(6, ezR6a );

    roundb(6, ezR6b );



    rounda(7, ezR7a );

    roundb(7, ezR7b );



    rounda(8, ezR8a );

    roundb(8, ezR8b );



    rounda(9, ezR9a );

    roundb(9, ezR9b );



    rounda(10, ezR10a );

    roundb(10, ezR10b );






} else {

  console.log("You didn't select a valid amount of players.");

}
var a=Math.floor(Math.random()*7)+1;
var-da=null;
var-ga=null;
如果(a==1){
da=“星期一”;
}否则如果(a==2){
da=“星期二”;
}否则如果(a==3){
da=“星期三”;
}如果(a==4),则为else{
da=“星期四”;
}如果(a==5),则为else{
da=“星期五”;
}否则如果(a==6){
da=“星期六”;
}否则如果(a==7){
da=“星期日”;
}
var play=prompt(“请选择1或2名玩家!最后至少有5000个积分才能获胜!”);
如果(播放=“1”){
var wel=confirm(“在一个暴风雨的“+da+”夜晚,闪电潜伏在天空中。你会为了一个赚几百万的机会而冒险吗?”);
}否则如果(播放==“2”){
确认(“在一个暴风雨的“+da+”夜晚,天空中潜伏着闪电。两个电力分销商为了争夺电力市场的主导权而展开了激烈的竞争。谁将主宰电力市场?”);
}否则{
ga=1;
}
var ezR1=Math.floor((Math.random()*2560)+500);
var ezR2=Math.floor((Math.random()*6650)+500);
var ezR3=Math.floor((Math.random()*6670)+600);
var ezR4=数学地板((数学随机()*7780)+600);
var ezR5=Math.floor((Math.random()*8120)+700);
var ezR6=数学地板((数学随机()*9540)+700);
var ezR7=Math.floor((Math.random()*1230)+800);
var ezR8=Math.floor((Math.random()*1134)+800);
var ezR9=数学地板((数学随机()*1223)+900);
var ezR10=Math.floor((Math.random()*1510)+1000);
var ezR1a=数学地板((数学随机()*2560)+500);
var ezR2a=Math.floor((Math.random()*6650)+500);
var ezR3a=Math.floor((Math.random()*6670)+600);
var ezR4a=数学地板((数学随机()*7780)+600);
var ezR5a=Math.floor((Math.random()*8120)+700);
var ezR6a=数学地板((数学随机()*9540)+700);
var ezR7a=数学地板((数学随机()*1230)+800);
var ezR8a=数学地板((数学随机()*1134)+800);
var ezR9a=数学地板((数学随机()*1223)+900);
var ezR10a=Math.floor((Math.random()*1510)+1000);
var ezR1b=Math.floor((Math.random()*2560)+500);
var ezR2b=Math.floor((Math.random()*6650)+500);
var ezR3b=数学地板((数学随机()*6670)+600);
var ezR4b=数学地板((数学随机()*7780)+600);
var ezR5b=Math.floor((Math.random()*8120)+700);
var ezR6b=数学地板((数学随机()*9540)+700);
var ezR7b=数学地板((数学随机()*1230)+800);
var ezR8b=数学地板((数学随机()*1134)+800);
var ezR9b=数学地板((数学随机()*1223)+900);
var ezR10b=Math.floor((Math.random()*1510)+1000);
var choozMany=Math.floor((Math.random()*4)+1);
var chooz=Math.random();
var amountOfPower=null;
var money=null;
var moneya=null;
var moneyb=null;
var-cabels=5;
var=2;
var-bacout=1;
Var1=1;
var d=0;
var-da=0;
var-db=0;
var vas=真;
var vasa=真;
var vasb=真;
var cabelsTake=500*cabels;
var bacout=2000*bacout;
var valu=“a”;
var valua=“a”;
var valub=“a”;
var gunka=真;
var gunkb=真;
var cabelsa=5;
var-clientsa=2;
var bacouta=1;
var-cabelsb=5;
var-clientsb=2;
var bacoutb=1;
函数轮(x){
警报(“回合“+x+”已开始!”);
}
函数s(){
控制台日志(“”);
}
函数Tell(a、b、c、d、z、e){
s();
console.log(“*************************************************”);
如果(e==n1 | e==n2){
控制台日志(“圆形“+z+”(“+e+”));
}否则{
控制台日志(“圆形”+z);
}
console.log(“-----------------------------------------”;
控制台日志(“学分:+a”);
控制台日志(“电源电缆:+b”);
console.log(“返回输出:+c”);
console.log(“客户端:+d”);
console.log(“-----------------------------------------”;
}
功能罢工(x){
控制台日志(“⚡ 卡布姆!⚡");
控制台日志(“雷击功率:+x+伏特”);
}
函数blowCable(){
log(“哦,不!你的一些电缆爆炸了!你有“+cabels+”左!”);
}
函数blowBacout(){
log(“哦,不!你的一些备份输出已经爆炸了!你还有”+bacout+“left!”);
}
//逻辑(cabelsTake、bacoutTake、clients、cabels、ezRX等);
功能逻辑(a、b、c、d、e){
var总=e-a;
var out=总计-b;
var-yon=a-e;
var-cab=500*d;
如果(yon>0){
var MoneyWerned=e/2*c+cab;
var结果=数学四舍五入(挣得的钱);
金钱+=结果;
console.log(“-----------------------------------------”;
console.log(“获得的学分:+结果”);
console.log(“覆盖的电缆/备份输出:无”);
console.log(“*************************************************”);
s();
}否则{
控制台日志(“”);
日志(“警报!警报!功率过大!”);
控制台日志(“”);
日志(“试图向备份输出端发送电源…”);
控制台日志(“⚠️违约!违约!输出无效!正在尝试重新发送。。。⚠️");
console.log(“*************************************************”);
s();
如果(输出<0){
var pen=3000+驾驶室;
钱+=笔;
console.log(“*************************************************”);
日志(“成功!电源转移”);
console.log(“获得的学分:+pen”);
console.log(“*************************************************”);
s();
}否则{
log(“警告!输入到大!”);
如果(选择z<0.75&&cabels>0){
cabels-=choozMany;
吹气电缆();
console.log(“覆盖电缆/备份输出:“+choozMany”);
console.log(“*************************************************”);
}否则如果(选择>0.75&&bacout>0){
bacout-=choozMany;
吹出();
console.log(“覆盖电缆/备份输出:“+choozMany”);
控制台日志(“*******************
var dayOfWeek = Math.floor(Math.random() * 7) + 1,
    dateLookup = {
        1: "Monday",
        2: "Tuesday",
        3: "Wednesday",
        4: "Thursday",
        5: "Friday",
        6: "Saturday",
        7: "Sunday"
    },
    da = dateLookup[dayOfWeek],
    ga = null;