In the fibo function you should return n when the value of n is less than or equal to 1. Or, you can return 1 when n is equal to 1 and you can return 0 when n is equal to 0.
function fibo(n) {
if (n <= 1) return n;
return fibo(n - 1) + fibo(n - 2);
}
Update: That was because I missed an important detail
Given a positive integer num, return the sum of all odd Fibonacci numbers that are less than or equal to num.
Fixed code:
function sumFibs(num) {
var sum = 0;
var fib = 0;
while (sum <= num) {
var currentFib = fibo(fib);
if (currentFib %2 === 1 && currentFib <= num) {
sum += currentFib;
}
fib++;
}
return sum;
}
function fibo(n) {
if (n <= 1) return n;
return fibo(n - 1) + fibo(n - 2);
}
console.log(sumFibs(10));