...

# How to make calculator's actions continuous?

shedokan
05-29-2009, 03:27 PM
I have a calculator, and I can't make it do continuous actions like:
when you press a number and press + and 1 and then press = 3 times so the first number is added 3.

here's my code:

// here are the basic variables
this.current = '0';
this.memory = '0';
this.action : '';
this.max : 8;

// adds a digit to the end of this.current
if (this.current.length > this.max){
return false;
}
if(eval(this.current) == 0 && this.current.indexOf('.') == -1){
this.current = dig;
} else {
this.current += ''+dig;
}
this.updateDisplay();
},

// adds a dot to the end of this.current if it doesn't have any
if(this.current.length == 0){
this.current = '0.';
} else if(this.current.indexOf('.') == -1){
this.current = this.current+'.';
}
this.updateDisplay();
},

// this sets the current action like '+', it is executed on each press of an action button
setAction: function(act){
this.action=act;
this.memory=this.current;
this.current = '0';
},

and this.updateDisplay() is the function to update the display with this.current.

jmrker
05-29-2009, 05:02 PM
Need to see more of the program to see if this works, but it may be here: ;)

// this sets the current action like '+', it is executed on each press of an action button
setAction: function(act){
this.action=act;
this.memory=this.current;
this.current = '0';
},

You set the 'this.current' variable to zero rather that leave it as the value to be acted upon ???
with the subsequent presses of the '=' key. :eek:

Just a guess. :confused:
Try adding a few test alert()s to see intermediate values of calculator.
:)