Home » , » Recursion Faktorial Javascript

Recursion Faktorial Javascript

Posted by RezkyCpp: Practice Does Not Make Perfect on Friday, December 1, 2017

Berikut script javascript untuk perulangan faktorial, recursion javascript. Semoga dapat membantu

<!DOCTYPE html>
<html>
<head>
    <title>Factorial calculation with a recursive function</title>
    <style type="text/css">
        p {margin: 0;}
    </style>

    <script type="text/javascript">
        var output= "";
        var input = parseInt(window.prompt("Please input the number"));
        document.writeln("<h1> Factorials of 0 to " + input + " </h1>");
        function calculateFactorials (){
            for (var i=0; i <= input; i++){
                output += "" + i + "! = " + factorial(i) + "<br>";
  
            document.getElementById("hasil").innerHTML=output;
                              
            }
        }
        function factorial (angka){
            if(angka == 0) {
        return 1;
    } else {
        return angka * factorial(angka - 1);
    }
        }
        window.addEventListener("load", calculateFactorials, false);
    </script>
</head>
<body>
    <div id="results"><p id="hasil"></div>
</body>
</html>

Thanks for reading & sharing RezkyCpp: Practice Does Not Make Perfect

Previous
« Prev Post

0 comments:

Post a Comment

Search