Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body ng-app="myApp" ng-controller="controller">
<div>{{game.timerValue}}</div>
  <input type="button" ng-click='startGame()'>
</body>
</html>
 
var app = angular.module('myApp', ['myApp.controllers']);
angular.module('myApp.controllers', []).controller('controller', ['$scope', function($scope) {
  
$scope.game = {
    "started"    : false,
    "timerValue" : 60,
    "score"      : 0,
    "question"   : "? ? ?",
    "message"    : "If all options are set up, then you may start!",
    "wrong"      : ""
  };
 // Handle Start Button click
  $scope.startGame = function () {    
    if($scope.game.timer) clearTimeout($scope.game.timer);
    $scope.game.score = 0;
    $scope.game.wrong = "";    
    $scope.game.message = "The game started!";
    $scope.game.timer = setInterval(function() {      
      $scope.game.timerValue -= 1;
      if( $scope.game.timerValue <= 0)
      {
        $scope.game.message = "Defeat! Time is out! Your score is " + $scope.game.score;
        clearTimeout($scope.game.timer);
      }
      $scope.$apply();
    },1000);
  };
}]);
Output 300px

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers