please what is wrong with this code below. i keep getting a number less than the answer
see below link to the challenge
function sumFibs(num) {
let prev = 0;
let result = 0;
for (let i = 1; i <= num; i=i+prev){
if (i % 2 == 1){
result+=i
}
prev = i - prev;
}
return result;
}
console.log(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/100.0.4896.75 Safari/537.36
i have really struggled to understand how i am going to calculate this series correctly. i have looked at links, watched youtube videos on this and i haven’t been able to.
A for loop is for when you run the loop body a fixed number of times? A while loop is for when you need to iterate until a condition is met. Which is closer to the challenge requirements?