I am newby about Javascript, and I am trying to create my own faculty calculator (math).
for example if you want to calculate 5 - faculty = 1*2*3*4*5 = 120
Now, I've managed to do this, but here's my problem:
My script works when I fill in an number, for example 5. When I calculated this, I want to calculate the 6 faculty, tats works too. But when I fill a number smaller than the first number (in this case 5), it doesn't work.
Here's my java script:
<html>
<head>
</head>
<body>
<script language="javascript">
var a = 1;
var n = 1;
function Calculate(x){
while (n<=x) {
a = a * n;
n++;
document.CalcFaculty.Output.value = a
}
}
</script>
<form name = "CalcFaculty">
<input type="text" name="Input" size="30"><br>
<input type="button" value="Calculate n-faculty" onClick="Calculate(document.CalcFaculty.Input.value)">
<input type="reset" value="Reset"><br>
<input type="text" name="Output" size="30">
</form>
</body>
</html>
Someone can help me?
Thx in advance
