diff options
author | Saumit Dinesan <justsaumit@protonmail.com> | 2023-08-30 11:16:11 +0530 |
---|---|---|
committer | Saumit Dinesan <justsaumit@protonmail.com> | 2023-08-30 11:16:11 +0530 |
commit | f8a237e363b020e876f553520329046cf813da8e (patch) | |
tree | b9a7125d1c1c306ead6136b2eb833b2580bafff4 | |
parent | f5e5cfa6c26e6f41af74c33a5a6726e50ef164f1 (diff) |
LiveClass01: Js function for Factorial
-rw-r--r-- | Live-Class01/index.html | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/Live-Class01/index.html b/Live-Class01/index.html new file mode 100644 index 0000000..488ca28 --- /dev/null +++ b/Live-Class01/index.html @@ -0,0 +1,32 @@ +<!DOCTYPE html> +<html lang="en"> +<head> + <meta charset="UTF-8"> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> + <title>Factorial Calculator</title> +</head> +<body> + <h1> Factorial </h1> + <p>Factorial is a mathematical operation that involves the multiplication of a positive integer with all the smaller positive integers leading up to it. <br>It is denoted by the symbol "!" following a number. <br> For instance, the factorial of 5 (written as 5!) equals the product of 5 × 4 × 3 × 2 × 1, resulting in 120. </p> + <div> + <label for="numberInput">Enter a number:</label> + <input type="number" id="numberInput"> + </div> + <button type="submit" id="submitbutton">Submit</button> + <p id="result"></p> + <script> + function factorial(n) { + if (n==0){ + return 1; + } + return n*factorial(n-1); + } + const button = document.getElementById("submitbutton") + button.addEventListener("click", function() { + const input = document.getElementById("numberInput").value; + const result = factorial(input) + document.getElementById("result").innerText=`The factorial of ${input} is equal to ${result}`; + }); + </script> +</body> +</html>
\ No newline at end of file |