-1

I'm currently setting up a few formula calculators. On the one I have this formula:

vc=ds*π.ns/60000

with this script:

<script>
    (function () {
    function calculateVc(ds, ns) {
    return (ds * 3.14159265359 * ns / 60000);
    }

    var Vc = document.getElementById("VC");
    if (Vc) {
    Vc.onsubmit = function () {
        this.Vc.value = calculateVc(this.ds.value, this.ns.value);
        return false;
    };
    }
    }());
    </script>

Which works perfectly. And then I have the reverse formula: ns=vc*60000/(ds*π) with this script:

<script>
    (function () {
function calculateNs(ds, vc) {

    return (vc * 60000 / ds * 3.14159265359);
}

var Ns = document.getElementById("Ns");
if (Ns) {
    Ns.onsubmit = function () {
        this.ns.value = calculateNs(this.ds.value, this.vc.value);
        return false;
    };
}
    }());
    </script>

Which doesn't work as required. Reusing the first result in a backward formula gives different results than expected. I suppose it's either a formatting error or a typo.

Peter Noble
  • 675
  • 10
  • 21
  • How is this off-topic? "Ask about... Specific programming problems Software algorithms Coding techniques Software development tools" I asked a relevant question and even got a relevant answer. Do you guys just make up rules as you go along? Or is it a "seems to me personally" situation? – Peter Noble May 27 '14 at 05:35
  • 2
    You might want to keep reading past that point: "This question was caused by a problem that can no longer be reproduced or a simple typographical error" – Brad Larson May 27 '14 at 21:07
  • So is this one: http://stackoverflow.com/questions/3066421/writing-a-new-line-to-file-in-php for example, yet I see a significant difference in the reviews. – Peter Noble May 28 '14 at 05:33

1 Answers1

2

Try add a pair of parentheses:

return (vc * 60000 / ( ds * 3.14159265359 ));
Andrew
  • 5,290
  • 1
  • 19
  • 22