# URGENT Help Needed with JavaScript Calculator

Hi, all -

I've been using a little JavaScript calculator that I picked up somewhere on the Internet many, many years ago  in many of my Lectora e-courses and never noticed until today that it has a significant flaw, which is affecting one of the practice activities that I have in a course I'm currently working on.

The calculator works fine EXCEPT that, if I enter a decimal point followed by a zero and then a number, it removes the decimal point, deletes the zero, and turns the number into a whole number (for example, if I enter ".05" it changes it to "5"). If I enter, say, ".34" then it stays ".34" -- it's only when there's a zero after the decimal point that it has this problem and immediately after typing the 0, deletes the decimal point and the zero and types whatever comes next as a whole number.

Here is the code I've been using:

x = 0;
ops = "n";
token = 0;

function calc(op)
{ if(!isNaN(op) || op==".")
{ if(!token)
{ if(document.calculator.win.value == 0)
{ document.calculator.win.value = op; }
else
{ document.calculator.win.value = document.calculator.win.value + op; }
}
else
{ document.calculator.win.value = op;
token = 0;
}
return;
}
else
{ if(op=="C")
{ document.calculator.win.value = 0;
token = 0;
return;
}

if(op=="CE")
{ document.calculator.win.value = 0;
return;
}

if(op=="%")
{ document.calculator.win.value = document.calculator.win.value / 100.0;
token = 1;
return;
}

if(op=="+/-")
{ document.calculator.win.value = -document.calculator.win.value;
token = 1;
return;
}

if(op=="+" || op=="*" || op=="/" || op=="-" || op=="=")
{ token = 1;
if(ops!="n")
{ if(ops=="+")
{ x = x -(- document.calculator.win.value);
document.calculator.win.value = x;
}
if(ops=="-")
{ x = x - document.calculator.win.value;
document.calculator.win.value = x;
}
if(ops=="/")
{ x = x / document.calculator.win.value;
document.calculator.win.value = x;
}
if(ops=="*")
{ x = x * document.calculator.win.value;
document.calculator.win.value = x;
}
}
else
{ x = document.calculator.win.value; }

if(op!="=") { ops=op; }
else { ops="n"; }
return;
}
}
}

Unfortunately, I'm not a JavaScript coder and can't figure out how to fix this, despite having spent some time researching this problem and finding a discussion about it here (http://www.anaesthetist.com/mnm/javascript/calc.htm) that I think addresses it, but I can't figure out how to translate what I'm reading there into what changes I need to make in my version, since they're not written similarly enough for this non-coder to decipher. So, I'd be deeply grateful if someone can give me  the fixed code in a way that I can just copy and paste it into (or on top of) the contents of my existing calculate.js file (or just send me back my file all fixed).