Hi,
-
sumFibs(10) gets the correct answer (10) with my code
-
sumFibs(4) gets the correct answer (5) with my code.
I don’t get the correct answers for other numbers? Please can someone advise.
Your code so far
function sumFibs(num) {
let arr = [1,1]
let res = 0;
let oddTotal = 2;
for(let total = 0; total <= num; total += oddTotal){
let old = arr[arr.length - 2];
let newer = arr[arr.length - 1];
res = old + newer;
arr.push(res);
if (res % 2){
oddTotal += res;
}
}
return oddTotal;
}
sumFibs(4);
**Your browser information:**
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.84 Safari/537.36
Challenge: Sum All Odd Fibonacci Numbers
Link to the challenge: