scrimba
Solution for day 9 of #javascriptmas
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

Solution for day 9 of #javascriptmas
by Kris
AboutCommentsNotes
Solution for day 9 of #javascriptmas
by Kris
Expand for more info
main.js
run
preview
console
function sumOddFibonacciNumbers(num) {
// write code here.
const fibonacci = [0];
let something = 1;
let result = 0;

while( something < num ) {
fibonacci.push( something );
if (something % 2) result += something;
something = fibonacci[ fibonacci.length - 2] + fibonacci[ fibonacci.length - 1];
}

// console.log(fibonacci);
return result;
}


/**
* 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 2: "
,
1785
,
"result 1: "
,
10
,
/index.html
LIVE