zoukankan      html  css  js  c++  java
  • js 猜数字游戏

    <html>

    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

    <script>

     function makenum(){

        var a1=document.getElementById("a");

     var t=parseInt(Math.random()*8 + 1);

     a1.value=t;

     initCount();
    var start=Date;

     alert(start);

     }

     function initCount(){

       count=0;

     }


     
     function check(){

       var num=document.getElementById("a").value;

       var num1=document.getElementById("c").value;

       var check="0123456789";

       for(var i=0;i<num1.length;i++){

         var ran=num1.charAt(i);

      if(check.lastIndexOf(ran)<0){

          alert('请输入数字');

       return false;

      }

       }

       if(num1>num){

          alert('你猜的大了');

       count++;

       }else if(num1<num){

          alert('你猜的小了');

       count++;

       }else if(num1==num){

         count++;

         alert('你猜了'+count+'次,终于猜对了');

      initCount();

       }

     }

    </script>

    <body>

    <input type="password" id="a"/>

    <input type="button" value="生成随机数字"  onclick="makenum()"/><br>

    <input type="text" id="c"/>

    <input type="button" " value="看看对了没有" onclick="check()"/>

    </body>

    </html>

  • 相关阅读:
    MVC 数据库增删改查(2) 视图
    MVC 数据库增删改查(1)
    委托的4种写法
    wpf 多线程操作(2)
    wpf 多线程操作例(1)
    网络抓取邮箱
    wpf 点击新建弹出新的窗口
    wpf 数据绑定 联系
    wpf 在listview里添加数据
    面向对象:抽象基类,接口
  • 原文地址:https://www.cnblogs.com/helloaworld/p/5542438.html
Copyright © 2011-2022 走看看