Hi,
it seems to me, that the “hint” solution two does not work for input values 0 and 1 (giving results 1 and 1, instead of 0 and 2).:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/sum-all-odd-fibonacci-numbers
Have a nice day
there was a small recent change in the challenge, maybe the guide has not been updated yet
I will check later when I am at computer
@ILM, did you change the hint solution? It passes for me.
considering that the instructions are
Given a positive integer
num
, return the sum of all odd Fibonacci numbers that are less than or equal tonum
.
If the input is 0, I also expect 0 as output, and if the input is 1 I would also expect an output 2 as the beginning is [1, 1]
(as also said in the description)
but, the second solution returns 1
in both cases
and that is because of the first few lines
if (num < 0) return -1;
if (num === 0 || num === 1) return 1;
other than that, the provided solution pass all tests
Just, the outputs do not conform with challenge description in these cases
I am going to substitute those first two lines with if (num <= 0) return 0;
so that the case for input 1 can be calculated by the rest of the function
so also both solutions have the same outputs for the same inputs