Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
  • 2 commits
  • 2 files changed
  • 0 commit comments
  • 2 contributors
Showing with 3 additions and 13 deletions.
  1. +2 −0  calculator.html
  2. +1 −13 calculator.js
View
2  calculator.html
@@ -9,7 +9,9 @@
<input id="num-a" type="text"/>
<select id="operator">
<option>+</option>
+ <option>-</option>
<option>*</option>
+ <option>/</option>
</select>
<input id="num-b" type="text"/>
<input id="calcular" type="button" value="calcular"/>
View
14 calculator.js
@@ -1,5 +1,4 @@
$("#calcular").click(function() {
- var resultado;
regvalidation = /^[\d]+$/;
if (!regvalidation.test($("#num-a").text())){
alert('numero a invalido');
@@ -9,16 +8,5 @@ $("#calcular").click(function() {
alert ('numero b invalido');
return false;
}
- var numA = parseInt($("#num-a").val());
- var numB = parseInt($("#num-b").val());
-
- if ($("#operator").val() == "+") {
- resultado = numA + numB;
- }
-
- if ($("#operator").val() == "*") {
- resultado = numA * numB;
- }
- $("#resultado").html(resultado);
-
+$("#resultado").html(eval($("#num-a").val() + $("#operator").val() + $("#num-b").val()));
});

No commit comments for this range

Something went wrong with that request. Please try again.