Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>Study</title>
- </head>
- <body>
- <h1 id="mesg"></h1>;
- <script>
- 'use strict'
- /*
- 0! = 1
- n! = n * (n - 1)!
- (n - 1)! = (n - 1) * ( n - 2)!
- 3! -> 1 * 2 * 3
- */
- function fakt(n) {
- if (n == 0) { return 1; }
- return n * fakt(n - 1);
- }
- /*
- fakt(3) -> 3 * fakt(3 -1)
- fakt(2) -> 2 * fakst( 2 - 1)
- fakt(1) -> 1 * fakt(1 -1 )
- fakt(0) -> 1
- fakt(3) -> 3 * 2
- fakt(2) -> 2 * 1
- fakt(1) -> 1 * 1
- fakt(0) -> 1
- */
- console.log(fakt(3));
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement