自定义的一种猜大小的游戏


<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Titletitle>
    <script src="../angular.min.js">script>
    <script>
         var myapp=angular.module("myapp",[]);
         myapp.controller("myctrl",function ($scope) {
        $scope.check=function () {

            $scope.differ=Math.ceil(Math.random()*10);
            console.log($scope.differ);
            console.log($scope.guess);
            $scope.differ=$scope.guess-$scope.differ;
            $scope.number++;
        }
        $scope.reset=function () {
            $scope.guess="";
            $scope.differ=null;
            $scope.number=0;

        }
             $scope.reset();
         })
    script>
head>
<body ng-app="myapp" ng-controller="myctrl">
<p>请输入一个1--10的数p>
<p>一共猜了{{number}}次p>
<input type="text" ng-model="guess">
<button ng-click="check()">检查button>
<button ng-click="reset()">重置button>
<p>我输入的是{{guess}},与系统匹配的相差{{differ}}p>
<p ng-if="differ>0">猜大了,小一点p>
<p ng-if="differ<0">猜小了,大点p>
<p ng-if="differ==0" style="color: red">恭喜你,你人品真好p>


body>
html>

你可能感兴趣的:(自定义的一种猜大小的游戏)