Factorial of the input number

Factorial of a number is product of all integers from 1 up to the number ( inclusive ).
Factorial of 5 is 1*2*3*4*5 = 120
Or
n! = 1*2*3….n

Enter a number here


Output here
<html>
<head>
<title></title>
</head>
<body>
<input type="text" name="t1" id="t1">
<input type="button" value="Submit" onclick="show_factorial()">
<div id=d1></div>
<script type="text/javascript">
function show_factorial(){
x=document.getElementById("t1").value
x=parseInt(x)
if(Number.isInteger(x)){
b=1
for (i=1;i<=x;i++){
	  b=b*i
}
document.getElementById('d1').innerHTML="Factorial of "+x+" is : "+b
}else{
document.getElementById('d1').innerHTML="Enter an Integer  "	
}
}
</script>
</body>
</html>
isInteger()Checking if input number is integer or not
parseInt()function to convert string to number

Next lower value of any decimal number JavaScript Basic JavaScript variable
JavaScript Math Reference
Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com










    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer