Home  >  Article  >  Web Front-end  >  Angularjs guessing number function implementation method

Angularjs guessing number function implementation method

小云云
小云云Original
2018-02-06 09:08:161193browse

This article mainly introduces the function of guessing the number size in angularjs to everyone in detail. It has certain reference value. Interested friends can refer to it. I hope it can help everyone.


<body ng-app="myapp" ng-controller="myCtrl">
 <h2>猜一猜,多大值?(1-1000)</h2>
 我猜是:<input type="text" ng-model="guess">
 <button ng-click="check()">验证</button><button ng-click="reset()">再玩一次</button><br>
 <span ng-if="fil>0">您猜的数大了</span>
 <span ng-if="fil<0">您猜的数小了</span>
 <span ng-if="fil==0">您猜对了</span>
 <p>猜的次数<span>{{n}}</span></p>
</body>

js code:


<script src="angular.min.js"></script>
 <script>
  var myapp=angular.module("myapp",[]);
  myapp.controller("myCtrl",function ($scope) {
      //验证
   $scope.check=function () {
    console.log($scope.random); //根据差值判断显示、隐藏状态
    $scope.fil=$scope.guess-$scope.random;
    $scope.n++;

   };          //重置方法
   $scope.reset=function () {
    $scope.guess=null;
    $scope.fil=null;
    $scope.n = 0;           //得到随机数
    $scope.random=Math.ceil(Math.random()*1000);
   };
   $scope.reset();
  })



 </script>

Related recommendations:

Detailed example of implementing a guessing number game based on vue components

JavaScript implementation of a guessing number game example code

A simple guessing number program, sometimes runs correctly, sometimes Running result error

The above is the detailed content of Angularjs guessing number function implementation method. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn