diff options
-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 |