My code passes each test individually, but not all at once

Tell us what’s happening:
Describe your issue in detail here.

I don’t understand why my code won’t pass the challenge even though it returns the expected sum for each test parameter when I manually put them in.

For example, the parameter in the code below is 75025. When I execute, the test for 75025 passes but all others fail. If I change the parameter to 75024 and execute, the test for 75024 passes, but all others (including the 75025 test which just worked) fail.

Any ideas?

  **Your code so far**
let x = 0;
let y = 1;
let fib = 0;
let sum = 0;

function sumFibs(num) {

while(fib <= num){
  fib = x + y;

  if(fib % 2 != 0 && fib <= num){
    sum += fib;
  }

  y = x;
  x = fib;

}
console.log(sum)
return sum;
}

sumFibs(75025);
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:101.0) Gecko/20100101 Firefox/101.0

Challenge: Sum All Odd Fibonacci Numbers

Link to the challenge:

You should move these vars inside the function. Because every call of your function changes them.

2 Likes