15 lines
228 B
JavaScript
15 lines
228 B
JavaScript
|
function fibonacci(num){
|
||
|
var a = 1, b = 0, temp;
|
||
|
|
||
|
while (num >= 0){
|
||
|
temp = a;
|
||
|
a = a + b;
|
||
|
b = temp;
|
||
|
num--;
|
||
|
}
|
||
|
|
||
|
return b;
|
||
|
}
|
||
|
|
||
|
console.log(fibonacci(7));
|
||
|
console.log(fibonacci(23));
|