Tell us what’s happening:
So, I’m almost there, I think, but when the 75024 argument is run through the function it goes one number in the sequence beyond what it is supposed to. Any ideas why it is doing that? Any help would be appreciated.
Your code so far
function sumFibs(num) {
var notSum = 2;
var notArr = [1,1];
var arr = [1,1];
var junk;
while (notSum <= num){
var last = notArr.length-1;
var last2 = notArr.length-2;
junk = notArr[last] + notArr[last2];
notArr.push(junk);
if (junk % 2 != 0 ){
notSum = notSum + junk;
console.log( notSum);
arr.push(junk);
}
}
return arr.reduce(function (accumulator, currentValue) {
return accumulator + currentValue;
}, 0) ;
}
sumFibs(75024);
Your browser information:
Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36
.
Link to the challenge:
https://www.freecodecamp.org/challenges/sum-all-odd-fibonacci-numbers