2016-12-05 3 views
1

Ich schreibe eine einfache eckige js-Anwendung. Aber ich bin ziemlich neu in eckigen js.Alarmbox, wenn Bedingung in Winkel js übereinstimmt

Die Anwendung fragt Antwort für die Multiplikation von zwei Zahlen

enter image description here

Ich möchte, dass, wenn die Schaltfläche ‚Prüfen‘ geklickt wird, sollte die Funktion überprüfen, ob die Antwort richtig ist. Wenn die Antwort falsch ist, nur dann sollte eine Warnmeldung angezeigt werden.

Wie kann ich dies mit eckigen js tun?

var app = angular.module('myApp', []); 
 
app.controller('myCtrl', function($scope, $window) { 
 
    $scope.firstname = "John"; 
 
    $scope.showTable = false; 
 
    $scope.changeName = function() { 
 
    $scope.firstname = $scope.table; 
 
    } 
 

 
    $scope.generateRandomNumber = function() { 
 
    $scope.Rn = Math.floor(Math.random() * 31); 
 
    $scope.showTable = true; 
 
    } 
 

 
    $checkAnswer = function() { 
 
    //if ($scope.Rn * $scope.table == $scope.answer) 
 
    $window.alert("Right!"); 
 
    // return; 
 
    } 
 

 
    $scope.randomNumber = function() { 
 
    $scope.firstname = Math.floor(Math.random() * 31); 
 
    } 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> 
 
<!DOCTYPE html> 
 
<html> 
 

 
<body> 
 
    <div ng-app="myApp" ng-controller="myCtrl"> 
 
    <label> 
 
     Enter the table you want to practice : 
 
    </label> 
 
    <input type="text" ng-model="table" /> 
 
    <button ng-click="generateRandomNumber()"> 
 
     Start</button> 
 
    <h1 ng-show="showTable"> 
 
      {{table}} * {{Rn}} = 
 
      <input type="text" ng-model="answer" /> 
 
      <button ng-click="checkAnswer()"> 
 
       Check</button></h1> 
 

 
    </div> 
 

 
</body> 
 

 
</html>

Antwort

0

Sie haben einen Tippfehler in Ihrem Code. Sie sollten schreiben:

$scope.checkAnswer = function() { 
    //if ($scope.Rn * $scope.table == $scope.answer) 
    $window.alert("Right!"); 
    // return; 
    } 

intsead dies:

$checkAnswer = function() { 
    //if ($scope.Rn * $scope.table == $scope.answer) 
    $window.alert("Right!"); 
    // return; 
    } 
+0

Dank @initfail und Glovas sein . Das war so dumm !! – Dhanashree

0

wie ein einfacher Tippfehler Sieht ...

$checkAnswer = function() { 
    //if ($scope.Rn * $scope.table == $scope.answer) 
    $window.alert("Right!"); 
    // return; 
    } 

sollte

$scope.checkAnswer = function() { 
    //if ($scope.Rn * $scope.table == $scope.answer) 
    $window.alert("Right!"); 
    // return; 
    }