See the full calculator with HTML -> https://gist.github.com/1861120You should be able to drag that html file from github into a browser and start using it. I'm only putting the js below. The calculator works fine but JS Lint is telling me I have an unexpected 'function' doCalc line 9 character 1.Also just looking for some general tips on best practices and how this might be refactored. Any help is appreciated. Thank you.var type, n, r, formula;Math.factorial = function (n) {    if (n < 2) {        return 1;    }    return (n * Math.factorial(n - 1));}function doCalc(type) {    switch (type) {        case 'permutation':            n = document.permutation.T1.value;            r = document.permutation.T2.value;            formula = function() {                document.permutation.T3.value = Math.factorial(n) / Math.factorial(n - r);            }            break;        case 'combination':            n = document.combination.T1.value;            r = document.combination.T2.value;            formula = function() {                document.combination.T3.value = Math.factorial(n) / (Math.factorial(r) * Math.factorial(n - r));            }            break;    }    n = Number(n);    r = Number(r);    if (isNaN(n) || isNaN(r)) {        alert(Factorial requires a numberic argument.);        return null;    }    formula();}window.onload = function() {    document.getElementById('calculate-p').onclick = function() {        doCalc('permutation');    }    document.getElementById('calculate-c').onclick = function() {        doCalc('combination');    }}
JSLint says unexpected function doCalc
javascript
You are getting jslint errors because of missing semicolons (the function expressions) and there are a few space issues (function() -> function ()). I would also make a few other changes:Wrap with an IIFE and pass in globals [see also]Add a use strict; line to use strict es5 syntaxChange factorial to be iterative so it works on numbers > 3000 (the Firefox recursion limit)Get rid of the unused type variableMove the variables local to doCalc to actually be localExtract methods for the permutation and combination functions (and since we are already extending Math, why not put them there? - edit: I would prefer not doing it in the first place but didn't feel like suggesting that)Since the switch statement is now almost the same, simplify the code by replacing the string type parameter to be a function parameterInline the repetitive assignments to n and rResults(function (Math, window, document) {    use strict;    Math.factorial = function (n) {        var r = n;        while (n > 1) {            r = r * n;            n -= 1;        }        return r;    };    Math.permutation = function (n, r) {        return Math.factorial(n) / Math.factorial(n - r);    };    Math.combination = function (n, r) {        return Math.factorial(n) / (Math.factorial(r) *                Math.factorial(n - r));    };    function doCalc(formula) {        var n = Number(document.permutation.T1.value),            r = Number(document.permutation.T2.value);        if (isNaN(n) || isNaN(r)) {            window.alert(Factorial requires a numberic argument.);            return null;        }        document.permutation.T3.value = formula(n, r);    }    window.onload = function () {        document.getElementById('calculate-p').onclick = function () {            doCalc(Math.permutation);        };        document.getElementById('calculate-c').onclick = function () {            doCalc(Math.combination);        };    };}(Math, window, document));There is still more to do with this code. For example you shouldn't use the on* properties to attach events because it overrides existing ones.