Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem with my factorial script. 1

Status
Not open for further replies.

baum

Programmer
Aug 9, 2002
7
HK
i've written to find factorials for myself. i suppose 0!=1 but when i input 0, the result is not 1. please help. below is my script. thanks.

<script lanaguage = &quot;JavaScript&quot;>
<!--
function getFactorial()
{
var schVal = parseInt(document.formFactorial.schVal.value);

for (var num = 1; num <= 200; num++)
if (num = schVal)
break;

document.formFactorial.result.value = factorial (schVal);
}

function factorial(num)
{
if ( num <= 1 )
return 1;
else
return num * factorial (num - 1);
}
// -->
</script>

<form name = &quot;formFactorial&quot;>
<table border = &quot;0&quot;>
<tr>
<td>Input an integer:</td>
<td><input name = &quot;schVal&quot; type = &quot;text&quot;></td>
<td><input type = &quot;button&quot; value = &quot;Calculate&quot; onclick = &quot;getFactorial()&quot;></td>
</tr>
<tr>
<td>The factorial is:</td>
<td><input name = &quot;result&quot; type = &quot;text&quot;></td>
</tr>
</table>
</form>
 
thank you for your help, harmmeijer.
 
thank you for your help, harmmeijer.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top