Trouble with Javascript syntaxes and if Statement
Hi everyone,
Having some trouble with a simple function. Doing a simple calculation function with input fields for a variable a and b and the function is supposed to return a x b.
Having trouble though with if someone writes something else then a number in the input fields like a symbol or a letter e.g. @,f,g,% or some thing like that. Tried different variations and here is the idea of the code:
$scope.calculate = function(a,b) {
a = $scope.app.view.Home.wdg["textInput-1"].text;
b = $scope.app.view.Home.wdg["textInput-2"].text;
var q;
q = a * b;
if (typeof q !== 'number') {
$scope.app.view.Home.wdg["label-2"].text = "Write numbers";
}
else{
$scope.app.view.Home.wdg["label-2"].text = "The value is: " + q;
}
}
The problem is the if statement, the idea is that if q is a datatype anything under then a number the text label should say write numbers, else it should display the value of q.
But I try this in different variations and all I get is either the value of q or if you write symbols it display "NaN".
Someone know of to resolve this?

