Fibonacci Javascript
I am having trouble with developing a program that uses the Fibonacci numbers method. I need code that allows a user to enter a number into an input field and the number of the calculation with appear below. The number that are to be enter must be between 0 - 20, if a user enters a number outside this range an error message appears. I have the code for the error message appearing but i dont know how to work the fibonacci calculation in the code. If any1 can help me with this i would be most grateful
Thanks
Phil
[535 byte] By [
Phil23] at [2007-11-20 5:33:39]

# 1 Re: Fibonacci Javascript
You would have to use a for loop just counting up while adding the previous number.
function fibonacci(num){
if(num < 1 || num > 20){
alert('Number must be between 1 and 20!');
}
else{
var curnum = 1;
var prevnum = 0;
for(i=0;i<=num;i++){
curnum = curnum + prevnum;
prevnum = curnum;
}
alert("Fibonacci number is " + curnum.toString());
}
}
# 2 Re: Fibonacci Javascript
Thankyou very much mate, i appreciate your help, it works great!