建站软件 优化软件 编程软件 网页辅助 站群程序 网站程序 图像处理 资源教程 字体下载 推荐软件


您的位置:首页 > javascript学习 > 用javascript实现数学运算

用javascript实现数学运算

时间:2015-09-20 13:55:46  来源:免费模板网 作者:风雪 阅读次数 tags数学运算

分享一个javascript代码实现的运算程序,有可能在你以后的项目中会用的到
<html>
 
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>考验你的心算能力</title>
 
</head>
 
<body>
 
<SCRIPT LANGUAGE="JavaScript"><!--
 function es() {    
 alert("请先作好准备.")         
 x=0    
 var today=new Date()    
 sec=0    
 for (i=1;i<=5;i++) {             
 sec=today.getSeconds()        
 rand1 = 31        
 while ( rand1 > 30 ) {            
 rand1 = Math.random()*sec*100           
 rand1 = Math.ceil(rand1)        
 }        
 rand2 = Math.random()        
 if (rand2>0.5) { 
 mes="加上 "; 
 mes1=" 到 "; 
 y=rand1 
 }                  
 else{ 
 mes=" 减去 " ; 
 mes1=" 从 "; 
 y=-rand1
 }    
 x1=x    
 x=x+y    
 if (x<0) { 
 mes="加上 "; 
 mes1=" 到 "; 
 x=x1+rand1 
 }    
 alert("请把原来结果"+mes+rand1+mes1+". ")                
 }    
 alert("请仔细想一下最后的结果.")    
 alert("最后结果为 "+x+" , 你算对了吗 ?")
 } 
 //-->
 </SCRIPT><FORM NAME="f"><INPUT TYPE="button" VALUE="开始啦" onClick="es()">
 
</body>
 
</html>

本文地址:https://www.freemoban.com/javascript/2015/0920/2470.html

猜你喜欢
栏目推荐
模板推荐

Copyright:www.freemoban.com 免费模板网 All Rights Reserved 网站备案:辽ICP备19014872号-2   辽公网安备 21010602000376号  辽公网安备:42900402000182号

免责声明:本站部分资源来自互联网收集,版权归原创者所有,如果侵犯了你的权益,我们会及时删除侵权内容,联系QQ:1615187561 谢谢合作!