MathCurvesSurfacesWallpaper GroupsGallerySoftwarePOV-Ray
ProgramingLinuxPerl PythonHTMLCSSJavaScriptPHPJavaEmacsUnicode ♥
Web Hosting by 1&1

JavaScript Example: Recursion

Xah Lee,

This page shows a example defining a factorial function, using recursion.

function ff(n) {
    if (n < 0)  { return -1; }

    if (n == 0) {
        return 1;
    }
    else {
        return (n * ff(n - 1));
    }
}

document.getElementById("id0f837").onclick = function(){ alert(ff(5));};

to see result.

blog comments powered by Disqus