Skip to content

Commit

Permalink
operacoes de soma e multiplicacao
Browse files Browse the repository at this point in the history
  • Loading branch information
douglasrodrigo committed Mar 14, 2013
1 parent 31f49db commit 1e94ec2
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions calculator.js
@@ -1,12 +1,16 @@
$("#calcular").click(function() {
regvalidation = /^[\d]+$/;
if (!regvalidation.test($("#num-a").text())){
alert('numero a invalido');
return false;
var resultado;

var numA = parseInt($("#num-a").val());
var numB = parseInt($("#num-b").val());

if ($("#operator").val() == "+") {
resultado = numA + numB;
}
if (!regvalidation.test($("#num-b").text())){
alert ('numero b invalido');
return false;

if ($("#operator").val() == "*") {
resultado = numA * numB;
}
$("#resultado").html(eval($("#num-a").val() + $("#operator").val() + $("#num-b").val()));
$("#resultado").html(resultado);

});

0 comments on commit 1e94ec2

Please sign in to comment.