Skip to content

Instantly share code, notes, and snippets.

@ddeveloperr
Created November 15, 2015 08:13
Show Gist options
  • Select an option

  • Save ddeveloperr/253cd282a7affb63b6e6 to your computer and use it in GitHub Desktop.

Select an option

Save ddeveloperr/253cd282a7affb63b6e6 to your computer and use it in GitHub Desktop.
Guess The Number game
<html>
<head>
<title>Guess The Number game!</title>
<link href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
</head>
<body ng-app="app">
<div class="container" ng-controller="GuessTheNumberController">
<h2>Guess the Number !</h2>
<p class="well lead">Guess the computer generated random number between 1 and 1000.</p>
<label>Your Guess: </label><input type="number" ng-model="guess"/>
<button ng-click="verifyGuess()" class="btn btn-primary btn-sm">Verify</button>
<button ng-click="initializeGame()" class="btn btn-warning btn-sm">Restart</button>
<p>
<p ng-show="deviation<0" class="alert alert-warning">Your guess is higher.</p>
<p ng-show="deviation>0" class="alert alert-warning">Your guess is lower.</p>
<p ng-show="deviation===0" class="alert alert-success">Yes! That"s it.</p>
</p>
<p class="text-info">No of guesses : <span class="badge">{{noOfTries}}</span><p>
</div>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.3/angular.js"></script>
<script type="text/javascript">
angular.module('app',[])
.controller('GuessTheNumberController', GuessTheNumberController);
function GuessTheNumberController($scope) {
$scope.verifyGuess = function () {
$scope.deviation = $scope.original - $scope.guess;
$scope.noOfTries = $scope.noOfTries + 1;
}
$scope.initializeGame=function() {
$scope.noOfTries = 0;
$scope.original = Math.floor((Math.random() * 1000) + 1);
$scope.guess = null;
$scope.deviation = null;
}
$scope.initializeGame();
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment