Write a program to find the factorial of any number

HTML CodeTry it

<!-- Write a program to find the factorial of any number. -->

<body>
   <div class="body">
      <div><input type="number" id="num1" placeholder="Enter a number...." /></div>
      <div><input type="button" onclick="result()" value="Submit" /></div>
   </div>
   <p id="result"></p>
</body>

CSS CodeTry it

.body{
   padding: 15px;
}
input, select{
   padding: 10px;
   margin: 5px;
   width: 300px;
}
p{
   text-align: center;
   font-size: 30px;
   color: blue;
}

JavaScript CodeTry it

function result(){
   var n = Number(document.getElementById("num1").value);
   temp = 1;
   for(i=1;i<=n;i++){
      temp = temp*i;
   }
   document.getElementById("result").innerHTML = "Factorial is..." + temp;
}

OutputTry it

Comments

Popular posts from this blog

PHP Code to print first 10 Fibonacci Numbers

Create a simple HTML page to demonstrate the use of different tags

Use Tables to provide layout to your web page.