The following code will do the job:
<SCRIPT LANGUAGE=vbscript>
<!--
Function IsPrime(str)
str=trim(str) Dim bln,ctr bln=true ctr=1
if(cint(str)<1)then
IsPrime=false exit function end if
if(cint(str)=1 or cint(str)=2 or cint(str)=3)then
IsPrime=true exit function end if
for ctr=cint(str)-1 to 2 step -1 if(cint(str)mod(ctr)=0)then bln=false
end if
next IsPrime=bln End Function
Function IsEven(str) str=trim(str) if(str="0")then IsEven=true
exit function
end if if(cint(str)mod(2)=0)then IsEven=true
else IsEven=false end if
End Function
Sub main()
str=text1.value
Dim blnEven,blnPrime
if not(isnumeric(str))then msgbox "Not numeric value" exit sub
end if
if(IsEven(str))then msgbox "Even" else
msgbox "Odd" end if
if(IsPrime(str))then msgbox "prime" else
msgbox "not prime"
end if
End Sub
}
//-->
</SCRIPT>
2. Use the given function to generate the fibonnacci series.
FUNCTION fib (n)
if (N=0) or (N=1) then
Fib = 1
ElseFib = Fib (N- 1) + Fib (N-2) END If
END FUNCTION
3. Use the given function to determine the factorial
Function Factorial(n) Dim i
If n < 0 Then
Factorial = 0
Exit Function End If Factorial = 1
For i = 2 To n
Factorial = Factorial * i
Next
End Function