I want to make a working calculator. Now, i want to change between the operators.
Let's say I have + and -. Then, I have 2 numbers. The operator is between them.
If the value of the operator is +, it should calculate +. If the value of operator is -, it should calculate -.
I tried something like this but it doesnt work, help?
function Operator() {
if ($('#realOperator').val == ('+');){
var a = parseInt($('input[name=a]').val());
var b = parseInt($('input[name=b]').val());
$('#total').val(a+b);
}else
$('#total').val(a-b);
}
}
Information
#realOperator is the input with the operator
#total is the input with the result.
Thanks and sorry if even the syntax is wrong.. I'm new!
Aucun commentaire:
Enregistrer un commentaire