Tell us what’s happening:
I don’t know what’s wrong with this code of mine. I just tried something different but ain’t able to find where I did wrong. Please have a look.
Your code so far
function sumFibs(num) {
//finds fibonacci in O(1) time
function fib(val) {
var phi = (1 + Math.sqrt(5)) / 2;
return Math.round(Math.pow(phi, val) / Math.sqrt(5));
}
var sum = 0;
for(var i = 1; i <= num; i++) {
var val = fib(i);
while(val <= num) {
if(val % 2 !== 0) {
sum = sum + val;
}
}
}
return sum;
}
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36
.
Link to the challenge: