This returns an error of “Unexpected token ‘sumFibs(num) {.’”
An array with two values is set. The formula for each term is provided. While terms are less than or equal to argument, and odd, add them to the sequence. Find the sum of each term with a collector called sum. Return sum. The problem could be in the if statement or the braces. Does something not make sense?
sumFibs(num) {
let sequence = [0,1];
let term = sequence[sequence.length - 1] + sequence[sequence.length - 2];
let sum = 0;
while (term <= num) {
if (term % 2) {
sequence.push(term);
sum += term;
}
}
return sum;
}
sumFibs(7);
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36 Edg/88.0.705.63
.
Challenge: Sum All Odd Fibonacci Numbers
Link to the challenge: