<!-- 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>
.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;
}
Comments
Post a Comment