Q:

jQuery calculator; subtraction trouble

I'm doing a basic calculator for class (like Google's when you type in "calculator" in browser) and I'm currently stuck in the subtraction operation. Brief explaining: when I click #buttonless, a variable "num1" is stored, and then the "screen" goes to zero. Then, when I click #buttonequal, a variable "num2" is also stored, and from there jQuery subtracts both numbers.
The thing is, when I follow the result I am given with another subtraction, instead of subtracting the calculator sums both numbers.
$("#buttonless").click(function(){
    var num1, num2, resultado;
    num1=parseFloat($("#screen").val());
    $("#screen").val(0);
    $("#buttonequal").click(function(){
        num2=parseFloat($("#screen").val());
        resultado=num1-num2;
        $("#screen").val(resultado);
        num1=0;
        num2=0;
    });
});

I've put an alert on bottom of the code and discovered that at the second time of subtracting (where the problem comes), the program subtracts 0, which seems to be "num1" at the time, to "num2", and then "num1" is replaced with the result I was given before, thus kind of "adding" the numbers.
For instance: I do the operation 3-1, and gives 2. But when I try to subtract 1 to that 2 (2-1) I'm given 3 instead of 1.
Any help would be appreciated. Thanks in advance.

A:

You have used an event handler inside another one. Try this:
var num1, num2, resultado;
$("#buttonless").click(function(){
        num1=parseFloat($("#screen").val());
        $("#screen").val(0);
});
$("#buttonequal").click(function(){
        num2=parseFloat($("#screen").val());
        resultado=num1-num2;
        $("#screen").val(resultado);
        num1=0;
        num2=0;
  });

If U can provide a demo, It would be easier to understand the problem.

