<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<META content="MSHTML 5.50.4913.1100" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face="Arial Black" size=2>I am calling a recursive function 
getFactorial(n) from the&nbsp;function&nbsp;Display(n) and trying to get it to 
display the answer in the TextBox fresult.&nbsp;&nbsp; If you look at the code 
you can see what I have tried.&nbsp; At the moment, when 6 is entered the alert 
message says "anwser equals __________".&nbsp; The code at the bottom works 
since it processes onLoad, but the&nbsp;first code&nbsp;is my problem 
code.</FONT></DIV>
<DIV><FONT face="Arial Black" size=2></FONT>&nbsp;</DIV>
<DIV><FONT face="Arial Black" size=2>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 
4.O1 Transitional//EN"<BR>&nbsp;"<A 
href="http://www.w3.org/TR/html4/loose.dtd">http://www.w3.org/TR/html4/loose.dtd</A>"&gt;<BR>&lt;HTML&gt;<BR>&lt;HEAD&gt;&lt;TITLE&gt; 
Recursive Function pg 192- Factorial of a Positive 
Integer&lt;/TITLE&gt;<BR>&lt;!--The original simply display the answer on the 
form upon loading.--&gt;<BR>&lt;SCRIPT LANGUAGE="javascript1.3" 
TYPE="text/javascript"&gt;<BR>&lt;!--<BR>// If 6 is entered, the answer is 
720.&nbsp; It should appear in this.form.fresult.value.<BR>// What appears in 
fresult is 'undefined'.<BR>var n;<BR>function getFactorial(n) 
{<BR>&nbsp;if(n==6) {<BR>&nbsp;alert("n equals " + n);<BR>&nbsp;}<BR>&nbsp;var 
Result = "";<BR>&nbsp;if(n &gt; 0) {<BR>&nbsp;&nbsp;result = n * 
getFactorial(n-1);<BR>&nbsp;}else if(n == 0) {<BR>&nbsp;&nbsp;Result = 
1;<BR>&nbsp;}else{<BR>&nbsp;&nbsp;Result = null;<BR>&nbsp;}<BR>&nbsp;return 
(Result);<BR>}<BR>//answer = getFactorial(n);&nbsp; this gets a 'n is null' 
message</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face="Arial Black" size=2>//function Display(n) {<BR>&nbsp;//var 
n;<BR>&nbsp;//var answer;<BR>&nbsp;//document.doIt.fresult.value = 
getFactorial(n);<BR>&nbsp;//getFactorial(n);<BR>&nbsp;//answer = 
getFactorial(n);<BR>&nbsp;//alert("answer equals " + 
answer);<BR>&nbsp;//document.doIt.fresult.value = 
getFactorial(n);<BR>&nbsp;//document.doIt.fresult.value = 
answer;<BR>//}<BR>//--&gt;<BR>&lt;/SCRIPT&gt;<BR>&lt;/HEAD&gt;<BR>&lt;body&gt;<BR>&lt;script 
text="text/javascript"&gt;<BR>&lt;!--<BR>function Display(n) {<BR>&nbsp;var 
n;<BR>&nbsp;var answer;<BR>&nbsp;//document.doIt.fresult.value = 
getFactorial(n);<BR>&nbsp;//getFactorial(n);<BR>&nbsp;answer = 
getFactorial(n);<BR>&nbsp;alert("answer equals " + 
answer);<BR>&nbsp;//document.doIt.fresult.value = 
getFactorial(n);<BR>&nbsp;//document.doIt.fresult.value = 
answer;<BR>}<BR>//--&gt;<BR>&lt;/script&gt;<BR>&lt;h3&gt;Compute factorial n! of 
a positive integer number n&lt;/h3&gt;<BR>&lt;hr&gt;<BR>&lt;form 
NAME="doIt"&gt;<BR>Enter integer n:<BR>&lt;input type="text" name="fn" 
size="2"&gt;entry:<BR>&lt;input type="text" name="fresult"&nbsp; 
size="40"&gt;<BR>&lt;br&gt;<BR>&lt;input type="button" name="compute" 
value="Compute n!" onClick="Display(this.form.fn.value)"&gt; 
<BR>&lt;/form&gt;<BR>&lt;/body&gt;<BR>&lt;/HTML&gt;</FONT></DIV>
<DIV><FONT face="Arial Black" size=2></FONT>&nbsp;</DIV>
<DIV><FONT face="Arial Black" size=2>CODE THAT WORKS ON LOAD:</FONT></DIV>
<DIV><FONT face="Arial Black" size=2>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 
4.O1 Transitional//EN"<BR>&nbsp;"<A 
href="http://www.w3.org/TR/html4/loose.dtd">http://www.w3.org/TR/html4/loose.dtd</A>"&gt;<BR>&lt;HTML&gt;<BR>&lt;HEAD&gt;&lt;TITLE&gt;Factorial 
of a Positive Integer&lt;/TITLE&gt;<BR>&lt;SCRIPT LANGUAGE="javascript1.3" 
TYPE="text/javascript"&gt;<BR>&lt;!--<BR>function getFactorial(n) {<BR>&nbsp;var 
result = "";<BR>&nbsp;if(n &gt; 0) {<BR>&nbsp;&nbsp;result = n * 
getFactorial(n-1);<BR>&nbsp;}else if(n == 0) {<BR>&nbsp;&nbsp;result = 
1;<BR>&nbsp;}else{<BR>&nbsp;&nbsp;result = 
null;<BR>&nbsp;}<BR>&nbsp;return(result);<BR></FONT><FONT face="Arial Black" 
size=2>}<BR>// 
--&gt;<BR>&lt;/SCRIPT&gt;<BR>&lt;/HEAD&gt;<BR>&lt;BODY&gt;<BR>&lt;SCRIPT 
TYPE="text/javascript"&gt;<BR>&lt;!--<BR>number = 6;<BR>var answer = 
"";<BR>answer = getFactorial(number);<BR>document.write("&lt;BR&gt;The factorial 
of " + number + " is: " + answer + '&lt;BR&gt;');<BR>// 
--&gt;<BR>&lt;/SCRIPT&gt;<BR>&lt;hr&gt;<BR>&lt;P&gt;To find the factorial of a 
positve integer (represented by n), you find the product of all integers 1 
through n.&nbsp; To find the factorial of 6, written 6!, calculate the 
following.&lt;BR&gt;<BR>6! = 6 x 5 x 4 x 3 x 2 x 
1&lt;BR&gt;<BR>&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;= 
720&lt;/P&gt;<BR>&lt;HR&gt;<BR>&lt;H3 ALIGN="center"&gt;Here is the code for the 
display above.&lt;/H3&gt;<BR>&lt;P&gt;Please remember that the left and right 
arrows used in HTML are replaced with paranethesis so that the code can be 
displayed in an orderly fashion..&lt;/P&gt;<BR>&lt;CODE STYLE="color: #0000CC; 
font-size: x-small; font-weight: bold;"&gt;<BR>&lt;PRE&gt;<BR>(SCRIPT 
LANGUAGE="javascript1.3" TYPE="text/javascript")<BR>(!--<BR>function 
getFactorial(n) {<BR>&nbsp;var result = "";<BR>&nbsp;if(n &gt; 0) 
{<BR>&nbsp;&nbsp;result = n * 
getFactorial(n-1);<BR>&nbsp;&nbsp;document.write("result as it occurs in the 
function equals: " + result + '(BR)');<BR>&nbsp;}else if(n == 0) 
{<BR>&nbsp;&nbsp;result = 1;<BR>&nbsp;}else{<BR>&nbsp;&nbsp;result = 
null;<BR>&nbsp;}<BR>&nbsp;return(result);<BR>}<BR>// 
--)<BR>(/SCRIPT)<BR>(/HEAD)<BR>(BODY)<BR>(SCRIPT 
TYPE="text/javascript")<BR>(!--<BR>number = 6;<BR>var answer = "";<BR>answer = 
getFactorial(number);<BR>document.write("(BR)The factorial of " + number + " is: 
" + answer + '(BR)');<BR>// 
--)<BR>(/SCRIPT)<BR>&lt;/PRE&gt;<BR>&lt;/CODE.<BR>&lt;/BODY&gt;<BR>&lt;/HTML&gt;</FONT></DIV></BODY></HTML>