javascript基础实例:如何计算24点(2)

80酷酷网    80kuku.com

      function test(expn,a,b,c,d,m1,m2,m3)
    {
     var exp;
     var ret;
     exp = genExpress(expn,a,b,c,d,m1,m2,m3);//生成计算表达式
     eval("ret = "+exp);
     if ( ret - 24 < 0.1 && ret - 24 >= 0 )
     {
      exp = exp.replace(";","");
      exp = replaceAll(exp,"*","×");
      exp = replaceAll(exp, "/","÷");
      var have = false;
      for ( var i=0; i<counter; i++)
      {
           if ( exp == answer[i] )
   {
        have = true;
        break;
       }
      }
      if ( !have )
      {
       answer[counter] = exp;
       counter++;
       log("<font color=red><b>"+counter+":  "+exp+"</b></font>");
      }

     }
    }
   
    function replaceAll (streng, soeg, erstat)
    {
     var st = streng;
     if (soeg.length == 0)
      return st;
     var idx = st.indexOf(soeg);
     while (idx >= 0)       
     { 
      st = st.substring(0,idx) + erstat + st.substr(idx+soeg.length);
      idx = st.indexOf(soeg);
     }
     return st;
    }

        var n = new Array();//四个数字
   
    //接收四个输入框的数字,调用主程序
    function funCount()
    {
     n[0] = document.forms[0].fa.value;
     n = document.forms[0].fb.value;
     n = document.forms[0].fc.value;



分享到
  • 微信分享
  • 新浪微博
  • QQ好友
  • QQ空间
点击: