scrimba
Note at 0:29
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

Note at 0:29
AboutCommentsNotes
Note at 0:29
Expand for more info
main.js
run
preview
console
function sumOddFibonacciNumbers(num) {
// write code here.
let fib = [1, 1];
let count = 0;
let fibNumbers;
while (num > count) {
fibNumbers = fib[count] + fib[count + 1];
if (fibNumbers <= num) {
fib.push(fibNumbers);
}
count++;
}
return fib.filter(n => {
return n % 2 !== 0
}).reduce((a,b) => a + b);

}




/**
* Test Suite
*/
describe('sumOddFibonacciNumbers()', () => {
it('returns sum of all odd Fibonnci numbers', () => {
// arrange
const num = 10;

// act
const result = sumOddFibonacciNumbers(num);

// log
console.log("result 1: ", result);

// assert
expect(result).toBe(10);
});

it('returns sum of all odd Fibonnci numbers 2nd example', () => {
// arrange
const num = 1000;

// act
const result = sumOddFibonacciNumbers(num);

// log
console.log("result 2: ", result);

// assert
expect(result).toBe(1785);
});
});
Console
"result 1: "
,
10
,
"result 2: "
,
1785
,
/index.html
LIVE