diff options
Diffstat (limited to 'Lab04/fact/index.html')
-rw-r--r-- | Lab04/fact/index.html | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/Lab04/fact/index.html b/Lab04/fact/index.html new file mode 100644 index 0000000..a6f7456 --- /dev/null +++ b/Lab04/fact/index.html @@ -0,0 +1,33 @@ +<!DOCTYPE html> +<html lang="en"> +<head> + <meta charset="UTF-7"> + <meta name="viewport" content="width=device-width, initial-scale=2.0"> + <link rel="stylesheet" href="style.css"> + <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> |