Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

operacoes de soma e multiplicacao

  • Loading branch information...
commit 1e94ec27eb502fbfe51f32262db37a4cc86612db 1 parent 31f49db
@douglasrodrigo authored
Showing with 12 additions and 8 deletions.
  1. +12 −8 calculator.js
View
20 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);
+
});
Please sign in to comment.
Something went wrong with that request. Please try again.