+ 3
What is the problem in this Fibonacci codes ?
https://code.sololearn.com/WAqc0z7PLwMV/?ref=app https://code.sololearn.com/WCr25c1tZ9gG/?ref=app
3 Answers
+ 10
Increments are invalid:
// p+=f (1+1= p=2) & f+=p (1+2=3)
My last fibonacci was 5 or 6 months ago, but this works pretty well btw, maybe there is a best solution, i'm too lazy in this moment sry. :3
// t is a "temporary" variable
var p, f, i, t;
i = 0;
p = 1;
f = 0;
document.write(p + "<br />");
// 1
for (; i <= 10; i++) {
t = p;
p += f;
f = t;
document.write(p + "<br />");
}
+ 5
Actually p is the previous number , f is the fibnocci number , i is for the loop 10 times