• 当前位置:首页>>JavaScript教程>>JavaScript基础教程>>javascript基础实例:如何计算24点(3)
  • javascript基础实例:如何计算24点(3)
  •      n[3] = document.forms[0].fd.value;
         if ( n[0] > 0 && n[1] > 0 && n[2] > 0 && n[3] > 0 && n[0] < 14 && n[1] < 14 && n[2] < 14 && n[3] < 14 )
         {
          log("<font size=5><b>"+n[0]+", "+n[1]+", "+n[2]+", "+n[3]+"的24点答案:</b></font><br>");
          log("<input type='button' onclick='history.back(-1);' value=' 再来一次 '><br>");
          funMain();
          if ( counter == 0 )
          {
           log("没有答案!");
          }
         }
         else
         {
          alert("输入错误!");
         }
        }
       
        //主程序
        function funMain()
        {
            var m = new Array();
         //四种运算符
            m[0] = "+";
            m[1] = "-";
            m[2] = "*";
            m[3] = "/";
           
         //11种表达式
            var exp1 = "a m1 b m2 c m3 d;";
            var exp2 = "(a m1 b) m2 c m3 d;";
            var exp3 = "(a m1 b m2 c) m3 d;";
            var exp4 = "((a m1 b) m2 c) m3 d;";
            var exp5 = "(a m1 (b m2 c)) m3 d;";
            var exp6 = "a m1 (b m2 c) m3 d;";
            var exp7 = "a m1 (b m2 c m3 d);";
            var exp8 = "a m1 ((b m2 c) m3 d);";

    [1]

  • 上一篇:javascript基础实例:如何计算24点(2)
    下一篇:javascript基础实例:如何计算24点(4)