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