Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'More on why it's a trivial fix' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
More on why it's a trivial fix
Authored by: mcroft on May 25, '05 01:23:37PM
The key here isn't to change the add/sub/mult/div methods, but to intercept the keydown and add it to the display string.

This is how I handled the add key in the variant I posted. deferredEvaluation is a variable I set at startup to tell me which file to process. OpList is a list of operators that can't be entered twice (no "9++4"). The final "else" is the prior "case add" code to call function add if deferredEvaluation is false.

It took me more time to work through making and saving a preference, a back, flipping the app, etc., than it did to update the JavaScript.


var deferredEvaluation = true;
var OpList="^!()+-*/";
{...}
case "add":
if (deferredEvaluation) {		
    if (!display.length) {
        clearDisplay();
        break;
    };
    if (OpList.indexOf(display.substr(display.length-1,1)) != -1 ) {
        display = display.substr(0,display.length-1)
   };			
   if (display.length < 9)
        display = display + "+";
   break;
} else {
    if (a && !isResult && !resetDisplay) {
        performOp();
    } else {
        a = evaluator(display);
        isResult = false;
    }
    currentOp = buttonTitle;
    hiliteOp = buttonTitle;
    resetDisplay = true;
    break;
}


[ Reply to This | # ]