English

# Find Factorial of Number using JavaScript

Factorial calculator script allows you to find factorial of given number using JavaScript.

# Features

• Factorial script is used for all factorial calculations.
• Find factorial of any number, using this calculator script.
• We can handle this script easily and it works in all major browsers.

# Preview

Enter Value

Click select code button to copy factorial number script. Javascript Code

<!--Script by hscripts.com-->
<!-- Free javascripts @ https://www.hscripts.com -->
<html>
<title>Factorial Number Calculator Script</title>
<script type="text/javascript" src="https://www.hscripts.com/jquery.js"></script>
<style type='text/css'>
.tb7
{
background: white;
border: 1px solid #DDD;
box-shadow: 0 0 5px #DDD inset;
color: #666;
float: left;
width: 250px;
height: 40px;
outline: none;
}
.testbutton
{
text-align: center;
font-size: 15px;
cursor: pointer;
width: 100px;
height: 40px;
color: #4e4e4e;
}
</style>
<script type='text/javascript'>
var factorial = 1;
function getfact()
{
var sds = document.getElementById("dum");
if(sds == null)
{
alert("You are using a free package.\n You are not allowed to remove the tag.\n");
}
var sdss = document.getElementById("dumdiv");
if(sdss == null){
alert("You are using a free package.\n You are not allowed to remove the tag.\n");
}
if(sdss != null)
{
\$("#dispans").html("");
var value = \$("#factval").val();
var num = isNaN(value);
if(value=="")
{
\$("#factval1").html("Enter the value");
setTimeout(function() {
\$("#factval1").html("");
}, 3000);
}
else
{
if(value>170)
{
\$("#factval1").html("Entered value exceeds limit");
setTimeout(function() {
\$("#factval1").html("");
}, 3000);
}
else
{
\$("#factval1").html("");
for (var x=value; x>=1; x--)
{
factorial = factorial * x;
}
\$("#dispans").html("The Factorial of '"+value+"' is : <span style='color:#900B09;font-size: 18px;'>"+factorial+"</span>");
factorial=1;
}
}
}
}
function isNumberKey(id)
{
var no=eval('"'+id+'"');
var no1=eval('"'+id+'1"');
var number= document.getElementById(no).value;
var number1= document.getElementById(no1);
if(!number.match(/^[0-9]+\$/) && number !="")
{
document.getElementById(id).value="";
document.getElementById(id).focus();
number1.innerHTML="<font color='red'>Enter numbers only</font>";
setTimeout(function() {
\$("#factval1").html("");}, 3000);
}
}function resetval(){
\$("#factval").val("");
\$("#factval1").html("");
\$("#dispans").html("");}
</script>
<body><div align='center'>
<div align='center' style='color: #4e4e4e; font-size: 20px; padding-top: 50px;'>Factorial Number Calculator Script</div><br>
<span id='factval1' style='color:red;font-size:15px;font-family:arial,verdana,san-serif;'></span><br><br><table align='center'>
<tr><td style='font-family: arial,verdana,san-serif;font-size: 15px;color:#666;'>Enter Value : </td>
<td><input type='text' id='factval' class='tb7' maxlength='3' onkeyup="isNumberKey(this.id)" /> </td>
<td> <input type='button' onclick='getfact()' value='Get Factorial' class='testbutton'>  <input type='button' onclick='resetval()' value='Reset' class='testbutton'> </td>
</tr>
</table><br><div id='dispans' style='color: #2f4f4f;margin-top: 5px;'></div><br>
<div align=center style=" font-size: 10px;color: green;" id="dumdiv">
</body>
</html>

• Release Date - 28-11-2013
• For customization of this script or any script development, mail to support@hscripts.com

# Usage

• Copy paste the factorial number calculator script in your webpage.
• Now run the file in your browser to view the functionality of the script.