<script>
var myapp=angular.module("myapp",[]);
myapp.controller("mycat",function ($scope) {
$scope.cha=function () {
$scope.dtr=$scope.gruee-$scope.random;
$scope.num++;
}
$scope.chong=function () {
$scope.num=null;
$scope.gruee=null;
$scope.dtr=null;
$scope.random=Math.ceil(Math.random()*10);
console.log($scope.random);
}
$scope.chong();
});
</script>
<h3>请输入1-10的整数</h3>
<input type="text" ng-model="gruee"><button ng-click="cha()">检查</button><button ng-click="chong()">重置</button>
<p ng-if="dtr==0">猜对了</p>
<p ng-if="dtr<0">猜小了</p>
<p ng-if="dtr>0">猜大了</p>
<p>一共猜了<span>{{num}}</span>次</p>