【发布时间】:2017-05-12 11:55:18
【问题描述】:
斐波那契数列代码在这里
function fibonnica(g) {
var result, n;
if (g == 1) {
return g; //if enterd no is 1 then 1 that is very apparent
} else {
result = g; //7
n = g - 1; //6
while (n > 0) {
result *= n ///7*6 second time 7*5 and so on..
n = n - 1; //n=5
}
return result;
}
}
console.log(fibonnica(7)); //why 7 is the output
请只告诉错误而不是我想要推动自己的解决方案
【问题讨论】:
-
我猜你有
while(n<0){错字! -
其实这不是斐波那契数列而是阶乘计算
-
对不起,但它在其他网页的控制台中不起作用,我不知道为什么。
-
但是现在可以了
标签: javascript fibonacci